-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sugar anonymous procedure and procedure type fails on identity function #18447
Comments
Related: "Araq said => and -> were bad ideas for sugar.nim" |
This goes into the rabbit hole way deeper than my understanding. |
This works: import sugar, macros
let identity = (x: int) -> int => x Would be good if we could get a nicer error message to suggest doing this. |
not very sweet for a syntax sugar; and very limited compared to import macros,sugar
proc id0(a: int): int = a # generics allowed
let id1 = proc(a: int): int = a # generics not allowed
let id2 = (x: int) -> int => x # ditto
let id2 = (x: int) => x # alternative form
# vs alias PR: #11992
alias id4 = (a: int) ~> a # concrete type possible but not required
alias id5 = (a: auto) ~> a # generics allowed
alias id6 = a ~> a # so are untyped templates
# eg usage: callMe(s, (a,b) ~> a < b, c ~> c * 2) (and no function pointer indirection either) |
@timotheecour fixing the compiler's |
Passing a generic (implied by auto) to a proc (or more generally, a template, iterator, macro etc) requires first class symbols, which is exactly what #11992 does. |
So with #11992 this bug would be fixed too (i.e. |
Identity function fails to compile when using sugar function types.
Seem related to how "auto" type works with sugar function types.
Example
By rewriting the => macro, seems that the "auto" type of function argument is not smart enough
This fails to compile
This compiles successfully
Current Output
Expected Output
Version
The text was updated successfully, but these errors were encountered: