mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-11 22:08:54 +00:00
@@ -622,15 +622,15 @@ proc setVarType(c: PContext; v: PSym, typ: PType) =
|
||||
proc isPossibleMacroPragma(c: PContext, it: PNode, key: PNode): bool =
|
||||
# make sure it's not a normal pragma, and calls an identifier
|
||||
# considerQuotedIdent below will fail on non-identifiers
|
||||
result = whichPragma(it) == wInvalid and key.kind in nkIdentKinds
|
||||
result = whichPragma(it) == wInvalid and key.kind in nkIdentKinds+{nkDotExpr}
|
||||
if result:
|
||||
# make sure it's not a user pragma
|
||||
let ident = considerQuotedIdent(c, key)
|
||||
result = strTableGet(c.userPragmas, ident) == nil
|
||||
if key.kind != nkDotExpr:
|
||||
let ident = considerQuotedIdent(c, key)
|
||||
result = strTableGet(c.userPragmas, ident) == nil
|
||||
if result:
|
||||
# make sure it's not a custom pragma
|
||||
var amb = false
|
||||
let sym = searchInScopes(c, ident, amb)
|
||||
let sym = qualifiedLookUp(c, key, {})
|
||||
result = sym == nil or sfCustomPragma notin sym.flags
|
||||
|
||||
proc copyExcept(n: PNode, i: int): PNode =
|
||||
|
||||
@@ -1770,12 +1770,15 @@ proc applyTypeSectionPragmas(c: PContext; pragmas, operand: PNode): PNode =
|
||||
discard "builtin pragma"
|
||||
else:
|
||||
trySuggestPragmas(c, key)
|
||||
let ident = considerQuotedIdent(c, key)
|
||||
if strTableGet(c.userPragmas, ident) != nil:
|
||||
let ident =
|
||||
if key.kind in nkIdentKinds:
|
||||
considerQuotedIdent(c, key)
|
||||
else:
|
||||
nil
|
||||
if ident != nil and strTableGet(c.userPragmas, ident) != nil:
|
||||
discard "User-defined pragma"
|
||||
else:
|
||||
var amb = false
|
||||
let sym = searchInScopes(c, ident, amb)
|
||||
let sym = qualifiedLookUp(c, key, {})
|
||||
# XXX: What to do here if amb is true?
|
||||
if sym != nil and sfCustomPragma in sym.flags:
|
||||
discard "Custom user pragma"
|
||||
|
||||
10
tests/pragmas/mqualifiedmacro.nim
Normal file
10
tests/pragmas/mqualifiedmacro.nim
Normal file
@@ -0,0 +1,10 @@
|
||||
template t*(x:untyped): untyped =
|
||||
echo "template t"
|
||||
|
||||
import macros
|
||||
macro m*(name: static string, x: untyped): untyped =
|
||||
let newName = ident(name)
|
||||
result = quote do:
|
||||
type `newName` = object
|
||||
if result.kind == nnkStmtList:
|
||||
result = result[^1]
|
||||
14
tests/pragmas/tqualifiedmacro.nim
Normal file
14
tests/pragmas/tqualifiedmacro.nim
Normal file
@@ -0,0 +1,14 @@
|
||||
discard """
|
||||
output: '''
|
||||
template t
|
||||
'''
|
||||
"""
|
||||
|
||||
# issue #12696
|
||||
|
||||
import mqualifiedmacro
|
||||
proc p() {. mqualifiedmacro.t .} = # errors with identifier expected but a.t found
|
||||
echo "proc p"
|
||||
|
||||
type Foo {. mqualifiedmacro.m("Bar") .} = object
|
||||
doAssert Bar is object
|
||||
Reference in New Issue
Block a user