summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorcooldome <cdome@bk.ru>2020-04-08 10:28:09 +0100
committerGitHub <noreply@github.com>2020-04-08 11:28:09 +0200
commitf86fc5316af480336a2dcd899b3f7288819914e7 (patch)
tree24f915267a442847da8041f68b676270c6cfbcc2 /compiler
parent95fd8ae93ce8732eb5a979d4cd63e0350594318d (diff)
downloadNim-f86fc5316af480336a2dcd899b3f7288819914e7.tar.gz
fix #13909 (#13914) [backport:1.2]
Co-authored-by: cooldome <ariabushenko@bk.ru>
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semstmts.nim11
-rw-r--r--compiler/semtypes.nim48
2 files changed, 35 insertions, 24 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 215d554fb..992f05e32 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -1472,9 +1472,14 @@ proc semProcAnnotation(c: PContext, prc: PNode;
     if whichPragma(it) != wInvalid:
       # Not a custom pragma
       continue
-    elif strTableGet(c.userPragmas, considerQuotedIdent(c, key)) != nil:
-      # User-defined pragma
-      continue
+    else:
+      let ident = considerQuotedIdent(c, key)
+      if strTableGet(c.userPragmas, ident) != nil:
+        continue # User defined pragma
+      else: 
+        let sym = searchInScopes(c, ident)
+        if sym != nil and sfCustomPragma in sym.flags: 
+          continue # User custom pragma
 
     # we transform ``proc p {.m, rest.}`` into ``m(do: proc p {.rest.})`` and
     # let the semantic checker deal with it:
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 21b95d3f6..7fe23eb8e 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -1576,28 +1576,34 @@ proc applyTypeSectionPragmas(c: PContext; pragmas, operand: PNode): PNode =
 
     if p.kind == nkEmpty or whichPragma(p) != wInvalid:
       discard "builtin pragma"
-    elif strTableGet(c.userPragmas, considerQuotedIdent(c, key)) != nil:
-      discard "User-defined pragma"
     else:
-      # we transform ``(arg1, arg2: T) {.m, rest.}`` into ``m((arg1, arg2: T) {.rest.})`` and
-      # let the semantic checker deal with it:
-      var x = newNodeI(nkCall, key.info)
-      x.add(key)
-      if p.kind in nkPragmaCallKinds and p.len > 1:
-        # pass pragma arguments to the macro too:
-        for i in 1 ..< p.len:
-          x.add(p[i])
-      # Also pass the node the pragma has been applied to
-      x.add(operand.copyTreeWithoutNode(p))
-      # recursion assures that this works for multiple macro annotations too:
-      var r = semOverloadedCall(c, x, x, {skMacro, skTemplate}, {efNoUndeclared})
-      if r != nil:
-        doAssert r[0].kind == nkSym
-        let m = r[0].sym
-        case m.kind
-        of skMacro: return semMacroExpr(c, r, r, m, {efNoSemCheck})
-        of skTemplate: return semTemplateExpr(c, r, m, {efNoSemCheck})
-        else: doAssert(false, "cannot happen")
+      let ident = considerQuotedIdent(c, key)
+      if strTableGet(c.userPragmas, ident) != nil:
+        discard "User-defined pragma"
+      else:
+        let sym = searchInScopes(c, ident)
+        if sym != nil and sfCustomPragma in sym.flags: 
+          discard "Custom user pragma"
+        else:
+          # we transform ``(arg1, arg2: T) {.m, rest.}`` into ``m((arg1, arg2: T) {.rest.})`` and
+          # let the semantic checker deal with it:
+          var x = newNodeI(nkCall, key.info)
+          x.add(key)
+          if p.kind in nkPragmaCallKinds and p.len > 1:
+            # pass pragma arguments to the macro too:
+            for i in 1 ..< p.len:
+              x.add(p[i])
+          # Also pass the node the pragma has been applied to
+          x.add(operand.copyTreeWithoutNode(p))
+          # recursion assures that this works for multiple macro annotations too:
+          var r = semOverloadedCall(c, x, x, {skMacro, skTemplate}, {efNoUndeclared})
+          if r != nil:
+            doAssert r[0].kind == nkSym
+            let m = r[0].sym
+            case m.kind
+            of skMacro: return semMacroExpr(c, r, r, m, {efNoSemCheck})
+            of skTemplate: return semTemplateExpr(c, r, m, {efNoSemCheck})
+            else: doAssert(false, "cannot happen")
 
 proc semProcTypeWithScope(c: PContext, n: PNode,
                           prev: PType, kind: TSymKind): PType =