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 611191 - Functions can take only one Generic as argument, has to be the last one
Functions can take only one Generic as argument, has to be the last one
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Genie
0.7.x
Other Linux
: Normal normal
: ---
Assigned To: Jamie McCracken
Vala maintainers
: 682715 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2010-02-26 16:16 UTC by Felix Wolfsteller
Modified: 2012-08-29 03:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Genie code to demonstrate failcase (174 bytes, application/octet-stream)
2010-02-26 16:16 UTC, Felix Wolfsteller
  Details
Add support for optional parentheses surrounding a types arguments (2.84 KB, patch)
2012-08-26 22:51 UTC, Simon Feltman
none Details | Review

Description Felix Wolfsteller 2010-02-26 16:16:30 UTC
Created attachment 154766 [details]
Genie code to demonstrate failcase

In Genie w/ valac 0.7.10 the parser stumbles when he hits a comma after an "of" (generics).

def goodfunc (i: int, l : list of string)
works.

def badfunc (l : list of string, i : int)
doesnt compile
gives error: syntax error, expected `)' but got `:' with previous identifier

sample code attached.
Comment 1 Simon Feltman 2012-08-26 09:13:25 UTC
*** Bug 682715 has been marked as a duplicate of this bug. ***
Comment 2 Simon Feltman 2012-08-26 20:40:09 UTC
The issue is the parsing of type information after the ":" eats commas as if
they are part of the type info. This is so things like this can work:

 var blah = dict of int, string

This is ambiguous and broken in the context of a parameter list:

 def func(i: int, d: dict of int, string, l: list of string)

This could be fixed having the parser optionally recognize parens surrounding a
generic types argument list if more than one argument is needed:

 var blah = dict of (int, string)
 def func(i: int, d: dict of (int, string), l: list of string)

And possible should try to keep compatibility for this case:

 var blah = dict of int, string
Comment 3 Simon Feltman 2012-08-26 22:51:49 UTC
Created attachment 222502 [details] [review]
Add support for optional parentheses surrounding a types arguments

This fixes issues with a generics type specification list. The following works but is ambiguous in that the comma might be meant to specify argument separation for the function, not the generic spec:
    def func(d: dict of int, string)

This patch allows support for more arguments following the generic spec unambiguously:
    def func(d: dict of (int, string))
and
    def func(d: dict of (int, string), l: list of string)

I consider this somewhat of a workaround as the patch makes sure all current syntax will still work as in the first example: 
    def func(d: dict of int, string)

"int, string" are part of the dict specification. I ultimately consider this less than ideal and really parens should be forced for any generic spec which requires multiple arguments, but this would break existing expectations, as in:
    var d = dict of int, string
would need to change to:
    var d = dict of (int, string)

Another option to get the best of both worlds would be to force parens depending on context for multi arg generics. So simple variable typing could still use the ambiguous syntax while things like function defs and delegates would require multi arg generics to use parens.
Comment 4 Jamie McCracken 2012-08-29 03:29:26 UTC
Thanks patch accepted and comitted

It would probably make sense to deprecate dict and multiple generic args syntax that does not use parens