#Union union variant with struct variant containing generic struct pointer becomes invalid

1 messages · Page 1 of 1 (latest)

gaunt gulch
#

This code causes Expression_Atom to be an invalid union variant only when actually switched on. I could not manage to minimally reproduce it but it manifests in a bigger codebase with essentially the same code as below (everything else commented out). Removing the args field from Expression_Call makes the error go away. Does this break some union/generic rule that I'm not aware off? After flattening Expression_Atom into Expression everything is fine.

`Link :: struct(T: typeid) {
value: T,
next: ^Link(T),
}

Expression :: union {
Expression_Atom,
// ...
}

Expression_Atom :: union {
i64,
string,
Expression_Call,
}

Expression_Call :: struct {
name: string,
args: ^Link(Expression),
}

switch_atom :: proc(atom: Expression_Atom) {
switch a in atom {
case i64:
case string:
case Expression_Call:
case nil:
}
}
`
(sorry for the title lol)

pseudo fjord
#

First thought is you need $T: typeid for your struct definition

#
Link :: struct($T: typeid) {}
chrome swan
#

when you make a link are you wrapping the value in the union it's in, like this?

l := Link(Expression){value = Expression_Atom(1)}
gaunt gulch