Skip to content
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

nim-1.4.0 regression: expandMacros compilation error #15691

Closed
slonik-az opened this issue Oct 23, 2020 · 3 comments · Fixed by #21623
Closed

nim-1.4.0 regression: expandMacros compilation error #15691

slonik-az opened this issue Oct 23, 2020 · 3 comments · Fixed by #21623

Comments

@slonik-az
Copy link

The following code compiles (and runs) perfectly fine under 1.2.6 and 1.2.8 but fails compilation in 1.4.0

MWE code

https://play.nim-lang.org/#ix=2BF4

import std/macros

template mk_discard*(macroName: untyped): untyped =
  macro `macroName`(args: varargs[untyped]): untyped = discard

expandMacros:
  mk_discard(foo)

foo(a,b,c,1, 2, 3)

Produced output (nim-1.4.0)

Compilation fails with the following error message

macro foo(args`gensym0: varargs[untyped]): untyped =
  discard

/usercode/in.nim(6, 1) template/generic instantiation of `expandMacros` from here
/usercode/in.nim(7, 3) Error: illformed AST: macro foo(args`gensym0: varargs[untyped]): untyped =
  discard

Expected Output

The MWE code is expected to compile and produce no output when run. The expected behavior is observed under nim 1.2.8 and 1.2.6.

Additional Information

MacOS Mojave (10.14.6)

$ nim -v
Nim Compiler Version 1.4.0 [MacOSX: amd64]
Compiled at 2020-10-17
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 1caa193d9367c8da49c22ee3e124e10dda03caf3
active boot switches: -d:release
@timotheecour
Copy link
Member

timotheecour commented Oct 23, 2020

git bisect returns #15158:

commit fb58066b61b14f4a1d6cdb0f4a8f0a9ea4174d82
Author: Clyybber <darkmine956@gmail.com>
Date:   Thu Aug 27 15:50:59 2020 +0200

    Fix #5691 (#15158)

    * Fix #5691
    * Cleanup and thoughts
    * Use scope approach
    * Seperate defined/declared/declaredInScope magics
    * Fix declaredInScope
    * Update spec accordingly

/cc @Clyybber

@andreaferretti
Copy link
Collaborator

I did not investigate this thouroughly, but this may be also the reason why tests of https://github.com/andreaferretti/interfaced fail

@demotomohiro
Copy link
Contributor

This bug still exists in recent devel Nim.
This is minimal code to reproduce the bug:

import std/macros

macro simplifiedExpandMacros(body: typed): untyped =
  result = body

simplifiedExpandMacros:
  proc testProc() = discard

simplifiedExpandMacros:
  template testTemplate(): untyped = discard

# Error: illformed AST: macro testMacro(): untyped =
simplifiedExpandMacros:
  macro testMacro(): untyped = discard

expandMacros takes code block as typed and return it.
It cause illformed AST error only when it got macro declaration.

Nim version:

$ nim -v
Nim Compiler Version 1.7.1 [Linux: amd64]
Compiled at 2022-06-30
Copyright (c) 2006-2022 by Andreas Rumpf

git hash: bcff13debcbdd8108237c8033e4dc9c38bb331e0
active boot switches: -d:release

metagn added a commit to metagn/Nim that referenced this issue Apr 7, 2023
`semProcAux` has a check for `checkMinSonsLen(n, bodyPos + 1)`
@metagn metagn mentioned this issue Apr 7, 2023
Araq pushed a commit that referenced this issue Apr 11, 2023
`semProcAux` has a check for `checkMinSonsLen(n, bodyPos + 1)`
narimiran pushed a commit that referenced this issue Apr 26, 2023
`semProcAux` has a check for `checkMinSonsLen(n, bodyPos + 1)`

(cherry picked from commit be06446)
capocasa pushed a commit to capocasa/Nim that referenced this issue May 15, 2023
`semProcAux` has a check for `checkMinSonsLen(n, bodyPos + 1)`
capocasa pushed a commit to capocasa/Nim that referenced this issue May 16, 2023
`semProcAux` has a check for `checkMinSonsLen(n, bodyPos + 1)`
bung87 pushed a commit to bung87/Nim that referenced this issue Jul 29, 2023
`semProcAux` has a check for `checkMinSonsLen(n, bodyPos + 1)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants