Fast initialization of arrays of stucts outside of namespace of struct results in error.
namespace Foo {
public struct A {
int a;
int b;
int c;
}
}
namespace Bar {
int main (string[] args) {
Foo.A[] arr = {
{1,2,3},
{2,3,1},
{2,3,1},
};
return 0;
}
}
$ valac test.vala
test.vala:12.7-12.13: error: The name `A' does not exist in the context of `Bar.main'
{1,2,3},
^^^^^^^
test.vala:13.7-13.13: error: The name `A' does not exist in the context of `Bar.main'
{2,3,1},
^^^^^^^
test.vala:14.7-14.13: error: The name `A' does not exist in the context of `Bar.main'
{2,3,1},
^^^^^^^
test.vala:12.7-12.13: error: expression type not allowed as initializer
{1,2,3},
^^^^^^^
test.vala:13.7-13.13: error: expression type not allowed as initializer
{2,3,1},
^^^^^^^
test.vala:14.7-14.13: error: expression type not allowed as initializer
{2,3,1},
^^^^^^^
Compilation failed: 6 error(s), 0 warning(s)
$ valac --version
Vala 0.48.5
Workaround is usinng using Foo;
, but that is not optimal.
It works if the A
is in the same namespace as main, in this example.
Edited by Gustav Hartvigsson