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 603056 - Using ternary operator ? in struct assignment leads to invalid C code
Using ternary operator ? in struct assignment leads to invalid C code
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Structs
0.11.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
: 684742 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-11-26 15:18 UTC by Michael 'Mickey' Lauer
Modified: 2013-04-30 07:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Set correct parent_statement for MemberInitializer (1.06 KB, patch)
2012-09-28 14:18 UTC, Simon Werbeck
none Details | Review
Set correct parent_statement for MemberInitializer (1.86 KB, patch)
2013-03-28 13:22 UTC, Luca Bruno
accepted-commit_now Details | Review

Description Michael 'Mickey' Lauer 2009-11-26 15:18:33 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)
Comment 1 Michael 'Mickey' Lauer 2011-03-03 15:46:27 UTC
Bumping version field, still a problem in 0.11.x.
Comment 2 A. Syukri Abdollah 2012-09-28 10:53:26 UTC
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_;
}
Comment 3 Simon Werbeck 2012-09-28 14:18:42 UTC
Created attachment 225337 [details] [review]
Set correct parent_statement for MemberInitializer

Fixes bug 603056
Comment 4 Luca Bruno 2013-03-28 13:22:50 UTC
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.
Comment 5 Luca Bruno 2013-03-28 13:23:30 UTC
Review of attachment 240047 [details] [review]:

.
Comment 6 Luca Bruno 2013-03-29 19:28:59 UTC
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.
Comment 7 Luca Bruno 2013-04-30 07:10:18 UTC
*** Bug 684742 has been marked as a duplicate of this bug. ***