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

Pragma nodes in templates are completely unprocessed #24186

Closed
metagn opened this issue Sep 26, 2024 · 0 comments · Fixed by #24183
Closed

Pragma nodes in templates are completely unprocessed #24186

metagn opened this issue Sep 26, 2024 · 0 comments · Fixed by #24183

Comments

@metagn
Copy link
Collaborator

metagn commented Sep 26, 2024

Description

From Discord:

macro mymacro(typ: typedesc; def) =
  def

macro mymacro2(typ: typedesc; typ2: typedesc; def) =
  def

template mytemplate(typ: typedesc) =   # works
  proc myproc() {.mymacro: typ .} =
    discard

template mytemplate2(typ: typedesc) =   # Error: undeclared identifier: 'typ'
  proc myproc2() {.mymacro(typ) .} =
    discard
  
template mytemplate2(typ: typedesc, typ2: typedesc) =  # Error: undeclared identifier: 'typ'
  proc myproc3() {.mymacro2(typ, typ2) .} =
    discard
  
template mytemplate4() =  # works
  proc myproc4() {.mymacro2(string, int) .} =
    discard

mytemplate(string)
mytemplate2(string)      # fails to compile if uncommented
mytemplate3(string, int) # fails to compile if uncommented
mytemplate4()

Nim Version

all versions

Current Output

Error: undeclared identifier: 'typ'

Expected Output

compiles

Known Workarounds

calling the macro explicitly

Additional Information

Culprit is here, only colon expressions are checked:

Nim/compiler/semtempl.nim

Lines 541 to 544 in a275421

of nkPragma:
for x in n:
if x.kind == nkExprColonExpr:
x[1] = semTemplBody(c, x[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.

1 participant