Structs (#197) can currently only be read field-by-field. Positional destructuring in declaration order — mirroring the positional constructor — would allow:
struct Foo { a: Int, b: Int }
let f = Foo(1, 2);
let x, y = f;
assert_eq(x, 1);
assert_eq(y, 2);
Today both paths reject this cleanly:
- statically known type:
error[resolver]: Invalid unpacking of Foo
- dynamically typed receiver:
error[vm]: cannot unpack: expected a list, tuple, or string
Unpacking is currently defined only for lists, tuples, and strings.
Design questions
- Should struct unpacking also work in
for loops and other destructuring positions?
- Is partial unpacking (
let x, y = f on a 3-field struct) an error, like it presumably is for tuples?
- Should the analyser require the arity to match the field count at compile time when the struct type is known?
🤖
Structs (#197) can currently only be read field-by-field. Positional destructuring in declaration order — mirroring the positional constructor — would allow:
Today both paths reject this cleanly:
error[resolver]: Invalid unpacking of Fooerror[vm]: cannot unpack: expected a list, tuple, or stringUnpacking is currently defined only for lists, tuples, and strings.
Design questions
forloops and other destructuring positions?let x, y = fon a 3-field struct) an error, like it presumably is for tuples?🤖