summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2023-06-13 13:04:24 +0300
committerGitHub <noreply@github.com>2023-06-13 12:04:24 +0200
commitfda8b6f193e2e229488f76f18089f01eb08272fb (patch)
treeae3430a6bcfaa71060a89143b04c4cc381be15b1 /compiler
parent2e12d3e26bd39205a2aa61a8873173e579cbcb9e (diff)
downloadNim-fda8b6f193e2e229488f76f18089f01eb08272fb.tar.gz
strictly typecheck expressions in bracketed `emit` (#22074)
* strictly typecheck expressions in bracketed `emit`

* use nim check in test
Diffstat (limited to 'compiler')
-rw-r--r--compiler/pragmas.nim2
-rw-r--r--compiler/sem.nim1
-rw-r--r--compiler/semdata.nim1
3 files changed, 3 insertions, 1 deletions
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim
index b3ccaf224..9e4a0052d 100644
--- a/compiler/pragmas.nim
+++ b/compiler/pragmas.nim
@@ -629,7 +629,7 @@ proc pragmaEmit(c: PContext, n: PNode) =
     if n1.kind == nkBracket:
       var b = newNodeI(nkBracket, n1.info, n1.len)
       for i in 0..<n1.len:
-        b[i] = c.semExpr(c, n1[i])
+        b[i] = c.semExprWithType(c, n1[i], {efTypeAllowed})
       n[1] = b
     else:
       n[1] = c.semConstExpr(c, n1)
diff --git a/compiler/sem.nim b/compiler/sem.nim
index 54ea38ef9..de78667ba 100644
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -678,6 +678,7 @@ proc preparePContext*(graph: ModuleGraph; module: PSym; idgen: IdGenerator): PCo
   if result.p != nil: internalError(graph.config, module.info, "sem.preparePContext")
   result.semConstExpr = semConstExpr
   result.semExpr = semExpr
+  result.semExprWithType = semExprWithType
   result.semTryExpr = tryExpr
   result.semTryConstExpr = tryConstExpr
   result.computeRequiresInit = computeRequiresInit
diff --git a/compiler/semdata.nim b/compiler/semdata.nim
index 8235eba9c..e92698916 100644
--- a/compiler/semdata.nim
+++ b/compiler/semdata.nim
@@ -126,6 +126,7 @@ type
     libs*: seq[PLib]           # all libs used by this module
     semConstExpr*: proc (c: PContext, n: PNode; expectedType: PType = nil): PNode {.nimcall.} # for the pragmas
     semExpr*: proc (c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType = nil): PNode {.nimcall.}
+    semExprWithType*: proc (c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType = nil): PNode {.nimcall.}
     semTryExpr*: proc (c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.nimcall.}
     semTryConstExpr*: proc (c: PContext, n: PNode; expectedType: PType = nil): PNode {.nimcall.}
     computeRequiresInit*: proc (c: PContext, t: PType): bool {.nimcall.}