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 684742 - Soft assertion and invalid C code when using ternary operator to initialize structure
Soft assertion and invalid C code when using ternary operator to initialize s...
Status: RESOLVED DUPLICATE of bug 603056
Product: vala
Classification: Core
Component: Structs
0.18.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2012-09-24 21:48 UTC by Jim Nelson
Modified: 2013-04-30 07:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Minimal test case. (271 bytes, text/x-vala)
2012-09-24 21:49 UTC, Jim Nelson
Details

Description Jim Nelson 2012-09-24 21:48:38 UTC
With Vala 0.18.0 (and possibly older versions, I found this with brand-new code), I get soft assertions and bad C code when using a ternary operator to initialize a struct's fields.  For example:


struct Frotz {
    int nitfol;
}

void main(string[] args) {
    // This causes soft assertions and invalid C code
    Frotz f = Frotz() { nitfol = (args.length > 2) ? 42 : 23 };
    
    // this is only to prevent unused-variable compiler warnings
    f.nitfol = 0;
}

yields these errors:

** (valac:19708): CRITICAL **: vala_block_insert_before: assertion `stmt != NULL' failed

** (valac:19708): CRITICAL **: vala_block_insert_before: assertion `stmt != NULL' failed
/home/jim/test/test.vala.c: In function ‘_vala_main’:
/home/jim/test/test.vala.c:54:11: error: ‘_tmp0_’ undeclared (first use in this function)


Removing the ternary operator avoids the problem.
Comment 1 Jim Nelson 2012-09-24 21:49:02 UTC
Created attachment 225109 [details]
Minimal test case.
Comment 2 Luca Bruno 2013-04-30 07:10:18 UTC
Thanks for taking the time to report this bug.
This particular bug has already been reported into our bug tracking system, but we are happy to tell you that the problem has already been fixed. It should be solved in the next software version. You may want to check for a software upgrade.

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