Invalid static initializers generated
Commit 9c35019e (on main and 0.56.5) results in invalid static initializers being generated for nested structs.
Reproducer:
public struct Foo {
public weak string a;
}
public struct Bar {
public Foo foo;
}
class Maman {
public static Bar bar = {{"foo"}};
}
static void main() {}
Before 9c35019e would compile to:
VALA_EXTERN Bar maman_bar;
Bar maman_bar = {0};
// ...
static void
maman_class_init (MamanClass * klass,
gpointer klass_data)
{
maman_parent_class = g_type_class_peek_parent (klass);
((MamanClass *) klass)->finalize = maman_finalize;
{
Bar _tmp0_ = (Bar) {(Foo) {"foo"}};
maman_bar = _tmp0_;
}
}
Now compiles to:
VALA_EXTERN Bar maman_bar;
Bar maman_bar = (Bar) {(Foo) {"foo"}};
which is invalid. Compound literals (the thing that looks like a cast) are not allowed in a constant context, the initializer would need to be {{"foo"}}
in this case. GCC supports some compound literals in this context (that's why it only breaks when using nested structs), but that's not defined by the standard.
Edited by Marvin W