mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-06 04:57:49 +00:00
fixes #24186 When encountering pragma nodes in templates, if it's a language pragma, we don't process the name, and only any values if they exist. If it's not a language pragma, we process the full node. Previously only the values of colon expressions were processed. To make this simpler, `whichPragma` is patched to consider bracketed hint/warning etc pragmas like `{.hint[HintName]: off.}` as being a pragma of kind `wHint` rather than an invalid pragma which would have to be checked separately. From looking at the uses of `whichPragma` this doesn't seem like it would cause problems. Generics have [the same problem](a27542195c/compiler/semgnrc.nim (L619)) (causing #18649), but to make it work we need to make sure the templates/macros don't get evaluated or get evaluated correctly (i.e. passing the proc node as the final argument), either with #23094 or by completely disabling template/macro evaluation when processing the pragma node, which would also cover `{.pragma.}` templates. (cherry picked from commit911cef1621)
29 lines
668 B
Nim
29 lines
668 B
Nim
# issue #24186
|
|
|
|
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 mytemplate3(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)
|
|
mytemplate3(string, int)
|
|
mytemplate4()
|