awestlake87/helix

struct literals

Opened this issue · 0 comments

struct Blargh
    int @a
    String @b
    double @optional?: 0.0

// need the concrete Blargh type, or it will generate a structure with only a and b
blargh: Blargh {
    a: 12,
    b: "lalala"
}
print(blargh.optional) // 0.0

blargh = { ...blargh, a: 14, b: "rawr", optional: 2.5 }

// spreading incompatible structures is fine as long as non-optional values are initialized
other: { a: 98, i: 123 }
blargh = { ...blargh, ...other }

// error - incompatible because of i attribute and lack of non-optional b value
blargh = other

print(blargh.b) // rawr
print(blargh.a) // 98
print(blargh.optional) // 2.5