After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 577149 - Unable to use static field with an object in a different class
Unable to use static field with an object in a different class
Status: RESOLVED DUPLICATE of bug 543189
Product: vala
Classification: Core
Component: Objects
0.7.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2009-03-29 01:58 UTC by Simeon Visser
Modified: 2010-03-26 17:04 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Simeon Visser 2009-03-29 01:58:02 UTC
A static field with an object from some class is null when used in an other class. Here's an example:

public class Bar {

    public static /*const*/ Bar STATICBAR = new Bar ();
    
    public string printme { get; set; default = "bar"; }
}

public class Foo {

    public void func ( Bar bar ) {
        stdout.printf ( "%s", bar.printme );
    }

    public static int main ( string[] args ) {
        var c = new Foo ();
        c.func ( Bar.STATICBAR );
        return 0;
    }
}

The string is never printed as bar is null and the parameter assertion of the method func fails.

The code does work when the string printme and the static field are moved to the Foo class (so the static field then holds a Foo object).

I've commented const for STATICBAR as this causes the C code to be invalid (duplicate variables) but this has already been reported.
Comment 1 Michael 'Mickey' Lauer 2009-10-08 18:14:51 UTC
I think non-constant initializers are not valid in this context (see also https://bugzilla.gnome.org/show_bug.cgi?id=569259), but Vala fails to recognize this. Instead, it just does not create the actual object.
Comment 2 Jürg Billeter 2010-03-26 17:04:11 UTC
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find.

*** This bug has been marked as a duplicate of bug 543189 ***