You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a macro takes in a typed argument with a lambda in it, then uses that typed argument as a result; if it has to be checked again (in this case, because the return type is auto); it will give an "illformed AST" error. The error is most likely because the name of the lambda node is set to Sym ":anonymous".
Replace auto with void, int in the example, it will work. Whether or not there are parameters does not change the result, neither does where you use the lambda.
This breaks expandMacros for macros like capture.
Example
import macros
expandMacros:
(proc: auto=discard)()
# or discard (proc: auto = 1)()# or let _ = proc: auto = discard# as long as the return type is auto
Current Output
proc (): auto = discard ()
/usercode/in.nim(3, 1) template/generic instantiation of `expandMacros` from here
/usercode/in.nim(4, 4) Error: illformed AST: proc (): auto = discard
Expected Output
proc (): auto = discard ()
(this render is incorrect, but that's unrelated)
More basic example:
macrofoo(x: typed): untyped=result= x
foo:
(proc: auto=discard)()
This fixes it:
import macros
macrofoo(x: typed): untyped=result=copy x # first copyresult[0] =newEmptyNode() # then delete name
foo:
(proc: auto=discard)()
$ nim -v
Nim Compiler Version 1.5.1 [Windows: amd64]
Compiled at 2021-02-09
Copyright (c) 2006-2021 by Andreas Rumpf
git hash: 4576cf20af3df84a077427faf69d6bfb47821897
active boot switches:
The text was updated successfully, but these errors were encountered:
metagn
changed the title
expandMacros gives illformed AST with auto return type on lambda
Cannot reuse typed argument which has lambda with auto return type
Feb 9, 2021
metagn
changed the title
Cannot reuse typed argument which has lambda with auto return type
Cannot reuse typed argument which has lambda with auto return type
Feb 9, 2021
If a macro takes in a
typed
argument with a lambda in it, then uses that typed argument as a result; if it has to be checked again (in this case, because the return type isauto
); it will give an "illformed AST" error. The error is most likely because the name of the lambda node is set toSym ":anonymous"
.Replace
auto
withvoid
,int
in the example, it will work. Whether or not there are parameters does not change the result, neither does where you use the lambda.This breaks
expandMacros
for macros likecapture
.Example
Current Output
Expected Output
(this render is incorrect, but that's unrelated)
More basic example:
This fixes it:
The text was updated successfully, but these errors were encountered: