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 600564 - Assigning an array property from an array not doing anything
Assigning an array property from an array not doing anything
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Arrays
0.7.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2009-11-03 15:37 UTC by Michael 'Mickey' Lauer
Modified: 2010-07-17 17:08 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Michael 'Mickey' Lauer 2009-11-03 15:37:19 UTC
public struct Struct
{
        public string a;
        public int b;
}

public Struct[] createArray()
{
        var array = new Struct[] {};
        array += Struct() { a = "Hello", b = 10 };
        array += Struct() { a = "World", b = 42 };
        return array;
}

public class Klass
{
        public Struct[] arrayOfStruct { get; set; }
        public void run()
        {
                arrayOfStruct = createArray();
        }
}

void main()
{
        var obj = new Klass();
        obj.run();
        assert( obj.arrayOfStruct != null );
        assert( obj.arrayOfStruct[0].a == "Hello" );
        assert( obj.arrayOfStruct[1].a == "World" );
}

=============================================
This test program asserts due to obj.arrayOfStruct being null.
Comment 1 Jürg Billeter 2009-12-24 14:25:59 UTC
The issue here is that the generated code passes a possibly uninitialized (temporary) variable as array length when calling klass_set_arrayOfStruct. The variable is possibly uninitialized as the evaluation order of arguments is not defined in C and array and array length are passed as two different arguments.

We already handle this by creating appropriate comma expressions in the case of method calls, however, we apparently don't handle this yet when setting properties.

You can work around this issue by using an extra local variable:

public class Klass
{
        public Struct[] arrayOfStruct { get; set; }
        public void run()
        {
                var array = createArray();
                arrayOfStruct = array;
        }
}
Comment 2 Marc-Andre Lureau 2010-04-07 22:08:38 UTC
The generated code with 0.8.0.19-12e1 is correct and it no longer aborts.

        _tmp2_ = (_tmp1_ = createArray (&_tmp0_), _tmp1__length1 = _tmp0_, _tmp1_);
        klass_set_arrayOfStruct (self, _tmp2_, _tmp0_);
Comment 3 Michael 'Mickey' Lauer 2010-07-17 17:08:23 UTC
Awesome, thanks to everyone involved.