GNOME Bugzilla – Bug 620133
[Genie] null-coalescing syntax error.
Last modified: 2018-05-22 13:36:38 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
Created attachment 254522 [details] [review] Patch to fix error Hopefully this will fix this.
Does anyone have any comments on this? Specifically, any comments on my patch?
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
-- 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.