GNOME Bugzilla – Bug 603056
Using ternary operator ? in struct assignment leads to invalid C code
Last modified: 2013-04-30 07:10:18 UTC
public struct Foo { uint8 param; } void dosomething( bool on ) { var foo = Foo() { param = on ? 0 : 1 }; } void main() { } =============================================== mickey@opal:/tmp$ LANG=C valac s.vala ** (valac:19333): CRITICAL **: vala_block_insert_before: assertion `stmt != NULL' failed ** (valac:19333): CRITICAL **: vala_block_insert_before: assertion `stmt != NULL' failed s.vala:6.1-6.16: warning: method `dosomething' never used void dosomething( bool on ) ^^^^^^^^^^^^^^^^ s.vala:8.6-8.39: warning: local variable `foo' declared but never used var foo = Foo() { param = on ? 0 : 1 }; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ /tmp/s.vala.c: In function 'dosomething': /tmp/s.vala.c:52: error: '_tmp0_' undeclared (first use in this function) /tmp/s.vala.c:52: error: (Each undeclared identifier is reported only once /tmp/s.vala.c:52: error: for each function it appears in.) error: cc exited with status 256 Compilation failed: 1 error(s), 2 warning(s)
Bumping version field, still a problem in 0.11.x.
Here is the generated C on 0.17.5 The conditional statement is totally missing. void dosomething (gboolean on) { gint _tmp1_; Foo _tmp2_ = {0}; Foo foo; _tmp1_ = _tmp0_; memset (&_tmp2_, 0, sizeof (Foo)); _tmp2_.param = (guint8) _tmp1_; foo = _tmp2_; }
Created attachment 225337 [details] [review] Set correct parent_statement for MemberInitializer Fixes bug 603056
Created attachment 240047 [details] [review] Set correct parent_statement for MemberInitializer Fixes bug 603056. Updated with a test. Will commit it once back home. Thanks.
Review of attachment 240047 [details] [review]: .
commit fb7687a16cf78c9ecf19720a3c70271dfaf98967 Author: Simon Werbeck <simon.werbeck@gmail.com> Date: Fri Sep 28 16:13:05 2012 +0200 Set correct parent_statement for MemberInitializer Fixes bug 603056. This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.
*** Bug 684742 has been marked as a duplicate of this bug. ***