GNOME Bugzilla – Bug 600564
Assigning an array property from an array not doing anything
Last modified: 2010-07-17 17:08:23 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.
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; } }
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_);
Awesome, thanks to everyone involved.