On Thu, 2012-10-25 at 13:00 -0700, bsquared wrote:
> I attempted a simple test using this:
> 8< ------------------------------------------------
> private static const Set<string> STATIC_SET;
> static construct {
> STATIC_SET = new HashSet<string> ();
> STATIC_SET.add ("Hello");
> STATIC_SET.add ("World");
> }
> ------------------------------------------------ >8
>
> with this result:
> 8< ------------------------------------------------
> valac --pkg gee-1.0 hello_set.vala
> hello_set.vala:5.4-5.47: error: `Gee.Set<string>' not supported as type
> for constants
> private static const Set<string> STATIC_SET;
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> hello_set.vala:8.3-8.16: error: The name `add' does not exist in the
> context of `HelloTest.STATIC_SET'
> STATIC_SET.add("Hello");
> ^^^^^^^^^^^^^^
> hello_set.vala:9.3-9.16: error: The name `add' does not exist in the
> context of `HelloTest.STATIC_SET'
> STATIC_SET.add("World");
> ^^^^^^^^^^^^^^
> Compilation failed: 3 error(s), 0 warning(s)
> ------------------------------------------------ >8
>
>
> To my untrained eye this appears to indicate that I cannot use these as
> constants. If I drop 'const' from the declaration it compiles and runs
> correctly.This is the expected result - if the Set is constant, then you can't call the add method on it. It looks like the Gee Set type simply doesn't support being used as a constant. I think that the only types that you can actually use as constants in Vala are ones that compile to basic/simple C types, and therefore could be created using constant C initializers. If you have to write data to the object at run-time to fill it, it's not a compile-time constant, after all. This limits you to using things like arrays of structures, for example. If you really want a run-time initialized Set, then it will have to be non-const. -- Calvin Walton <[email protected]>
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ vala-list mailing list [email protected] https://mail.gnome.org/mailman/listinfo/vala-list
