Struct initializer assigns properties to a temporary copy of the struct
To reproduce:
// foo.vala
public struct Foo.Foo {
public int bar { get; set; }
public static Foo new() {
return Foo() { bar = 42 };
}
}
In the struct initializer, the property value for bar
is assigned to a temporary copy (_tmp1_
) of Foo.Foo
, having no effect on the result.
// foo.c (compiled)
void
foo_foo_new (FooFoo* result)
{
FooFoo _tmp0_ = {0};
FooFoo _tmp1_;
memset (&_tmp0_, 0, sizeof (FooFoo));
_tmp1_ = _tmp0_;
foo_foo_set_bar (&_tmp1_, 42);
*result = _tmp0_;
return;
}
void
foo_foo_set_bar (FooFoo* self,
gint value)
{
g_return_if_fail (self != NULL);
(*self)._bar = value;
}
// ...
$ valac --header foo.h --gir=Foo-0.gir --library foo --ccode foo.vala
$ valac --version
Vala 0.56.7