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 620133 - [Genie] null-coalescing syntax error.
[Genie] null-coalescing syntax error.
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Genie
0.8.x
Other Linux
: Normal normal
: ---
Assigned To: Jamie McCracken
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-05-31 01:10 UTC by san hoi
Modified: 2018-05-22 13:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to fix error (1.38 KB, patch)
2013-09-09 21:22 UTC, oliver.steven
needs-work Details | Review

Description san hoi 2010-05-31 01:10:34 UTC
I use recently git repository version vala.

[mymas@localhost Downloads]$ valac --version
Vala 0.8.0.188-2c5e

follwing case, 

init
	var name = "hello world"
	print ("%s", name != "" ? name : "unknown phrase")
	print ("%s", name ?? "unknown phrase") <- error syntax

error:

nullCoalescing.gs:4.21-4.21: error: syntax error, expected identifier
	print ("%s", name ?? "unknown phrase") <- error syntax
	                   ^
Compilation failed: 1 error(s), 0 warning(s)

http://live.gnome.org/Vala/Syntax
Comment 1 oliver.steven 2013-09-09 21:22:24 UTC
Created attachment 254522 [details] [review]
Patch to fix error

Hopefully this will fix this.
Comment 2 oliver.steven 2014-05-30 19:20:01 UTC
Does anyone have any comments on this? Specifically, any comments on my patch?
Comment 3 Al Thomas 2014-10-31 22:53:49 UTC
Review of attachment 254522 [details] [review]:

Firstly, good to see someone hacking on the Genie parser.

Secondly, your patch applies, but does not give the functionality required. I get the "syntax error, expected identifier" message, the same as the bug originator. I think you need to add ?? to the Genie scanner as well - valageniescanner.vala - this will then turn the ?? operator into the relevant token and you should then be away. The only other amendment needed is to add OP_COALESCING to the to_string() method of valagenietokentype.vala for proper syntax error messages.

Finally, in terms of documenting the feature I would say "Null values are avoided in Genie because, if unchecked for, they cause segmentation faults and also introduce three value logic that adds complexity to value checking. Genie, however, interfaces with C libraries that do return null values and the null coalescing operator provides a useful shorthand for setting a sensible default. For example:
init
    	a:string = c_binding_call()
        if a == null
                a = "sensible default"
        print ( a )

def c_binding_call():string
        return null

would become

init
    	a:string = c_binding_call() ?? "sensible default"
        print ( a )

def c_binding_call():string
        return null
Comment 4 GNOME Infrastructure Team 2018-05-22 13:36:38 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/102.