From 4601bb0255335e2c1dfc78ebc33312933215ee95 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 25 Apr 2024 00:43:29 +0800 Subject: fixes #23525; an 'emit' pragma cannot be pushed (#23537) fixes #23525 --- compiler/pragmas.nim | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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..