GNOME Bugzilla – Bug 611191
Functions can take only one Generic as argument, has to be the last one
Last modified: 2012-08-29 03:29:26 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.
*** Bug 682715 has been marked as a duplicate of this bug. ***
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
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.
Thanks patch accepted and comitted It would probably make sense to deprecate dict and multiple generic args syntax that does not use parens