Compiler warning when initializing property with constructor of implementation of interface with abstract property
The following code snippet causes a compiler warning:
interface Test {
public abstract string test { get; set; }
}
class TestImpl : Test {
public string test { get; set; }
}
void main() {
new TestImpl() { test = "Test" };
}
early_init.vala.c:376:17: warning: passing argument 1 of ‘test_set_test’ from incompatible pointer type [-Wincompatible-pointer-types]
376 | test_set_test (_tmp1_, _tmp0_);
| ^~~~~~
| |
| TestImpl * {aka struct _TestImpl *}
early_init.vala.c:92:22: note: expected ‘Test *’ {aka ‘struct _Test *’} but argument is of type ‘TestImpl *’ {aka ‘struct _TestImpl *’}
92 | test_set_test (Test* self,
This is because the function is compiled to:
void
_vala_main (void)
{
gchar* _tmp0_;
TestImpl* _tmp1_ = NULL;
TestImpl* _tmp2_;
_tmp0_ = g_strdup ("Test");
_tmp1_ = test_impl_new ();
test_set_test (_tmp1_, _tmp0_);
_g_free0 (_tmp0_);
_tmp2_ = _tmp1_;
_test_impl_unref0 (_tmp2_);
}
When changing main to
void main() {
var test = new TestImpl();
test.test = "Test";
}
the code is compiled to
void
_vala_main (void)
{
TestImpl* test = NULL;
TestImpl* _tmp0_;
_tmp0_ = test_impl_new ();
test = _tmp0_;
test_set_test ((Test*) test, "Test");
_test_impl_unref0 (test);
}
instead, which doesn't impose any warning (and also looks way cleaner in C, but less nice in Vala).
To upload designs, you'll need to enable LFS and have admin enable hashed storage. More information