mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
strictly typecheck expressions in bracketed emit (#22074)
* strictly typecheck expressions in bracketed `emit` * use nim check in test
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.}
|
||||
|
||||
12
tests/lookups/tambiguousemit.nim
Normal file
12
tests/lookups/tambiguousemit.nim
Normal file
@@ -0,0 +1,12 @@
|
||||
discard """
|
||||
cmd: "nim check $options $file" # use check to assure error is pre-codegen
|
||||
matrix: "; --backend:js" # backend shouldn't matter but at least check js
|
||||
"""
|
||||
|
||||
proc foo(x: int) = discard
|
||||
proc foo(x: float) = discard
|
||||
|
||||
{.emit: ["// ", foo].} #[tt.Error
|
||||
^ ambiguous identifier 'foo' -- use one of the following:
|
||||
tambiguousemit.foo: proc (x: int){.noSideEffect, gcsafe.}
|
||||
tambiguousemit.foo: proc (x: float){.noSideEffect, gcsafe.}]#
|
||||
Reference in New Issue
Block a user