summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2024-04-25 00:43:29 +0800
committerGitHub <noreply@github.com>2024-04-24 18:43:29 +0200
commit4601bb0255335e2c1dfc78ebc33312933215ee95 (patch)
treee9ec5bcbd681d75dcb6b25f9f473eecd6e243786
parenta5c1a6f042d800d7f0ff091c908cc1c8f9648442 (diff)
downloadNim-4601bb0255335e2c1dfc78ebc33312933215ee95.tar.gz
fixes #23525; an 'emit' pragma cannot be pushed (#23537)
fixes #23525
-rw-r--r--compiler/pragmas.nim13
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim
index a644639fe..4b871a500 100644
--- a/compiler/pragmas.nim
+++ b/compiler/pragmas.nim
@@ -480,6 +480,18 @@ proc processOption(c: PContext, n: PNode, resOptions: var TOptions) =
     # calling conventions (boring...):
     localError(c.config, n.info, "option expected")
 
+proc checkPushedPragma(c: PContext, n: PNode) =
+  let keyDeep = n.kind in nkPragmaCallKinds and n.len > 1
+  var key = if keyDeep: n[0] else: n
+  if key.kind in nkIdentKinds:
+    let ident = considerQuotedIdent(c, key)
+    var userPragma = strTableGet(c.userPragmas, ident)
+    if userPragma == nil:
+      let k = whichKeyword(ident)
+      # TODO: might as well make a list which is not accepted by `push`: emit, cast etc.
+      if k == wEmit:
+        localError(c.config, n.info, "an 'emit' pragma cannot be pushed")
+
 proc processPush(c: PContext, n: PNode, start: int) =
   if n[start-1].kind in nkPragmaCallKinds:
     localError(c.config, n.info, "'push' cannot have arguments")
@@ -487,6 +499,7 @@ proc processPush(c: PContext, n: PNode, start: int) =
   for i in start..<n.len:
     if not tryProcessOption(c, n[i], c.config.options):
       # simply store it somewhere:
+      checkPushedPragma(c, n[i])
       if x.otherPragmas.isNil:
         x.otherPragmas = newNodeI(nkPragma, n.info)
       x.otherPragmas.add n[i]