✓
Passing Passing: the compiler rejects this program as expected.
Code
// PINS: ref(T) with no possible home refuses at list:new — the same law
// as 698_016 on the store side. A field that can only ever hold -1 is
// not honoring the contract; it is voiding it.
import std/proto
import std/list
std/proto(Dog) {
hp: i64
}
std/proto(Owner) {
name: string
dog: ref(Dog)
}
std/list:new(Owner)
| list xs |> std/list:free(xs)
| err e |> _
Actual compiler output
error[KORU173]: std/list:new(Owner): field 'dog' is ref(Dog) but no store holds Dog rows — a ref field needs a home: a plural store whose row carries the target's fields (std/store:new(dogs, capacity: N) { Dog }); without one the field can only ever hold -1
--> tests/regression/600_STDLIB/698_OOP/698_018_list_ref_no_home_refused/input.k:16:0Compiler must reject:
Compilation must fail with a diagnostic.
Flows
flow ~std/proto click a branch to expand · @labels scroll to their anchor
std/proto (Dog, source: hp: i64)
flow ~std/proto click a branch to expand · @labels scroll to their anchor
std/proto (Owner, source: name: string
dog: ref(Dog))
flow ~new click a branch to expand · @labels scroll to their anchor
new (Owner)
Test Configuration
MUST_ERROR