mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-16 22:11:18 +00:00
makes 'reject' tests green
This commit is contained in:
@@ -851,6 +851,8 @@ proc genAsgn(c: PCtx; dest: TDest; ri: PNode; requiresCopy: bool) =
|
||||
gABC(c, ri, whichAsgnOpc(ri), dest, tmp)
|
||||
c.freeTemp(tmp)
|
||||
|
||||
template isGlobal(s: PSym): bool = sfGlobal in s.flags and s.kind != skForVar
|
||||
|
||||
proc genAsgn(c: PCtx; le, ri: PNode; requiresCopy: bool) =
|
||||
case le.kind
|
||||
of nkBracketExpr:
|
||||
@@ -872,7 +874,7 @@ proc genAsgn(c: PCtx; le, ri: PNode; requiresCopy: bool) =
|
||||
c.freeTemp(tmp)
|
||||
of nkSym:
|
||||
let s = le.sym
|
||||
if sfGlobal in s.flags:
|
||||
if s.isGlobal:
|
||||
withTemp(tmp, le.typ):
|
||||
gen(c, ri, tmp)
|
||||
c.gABx(le, whichAsgnOpc(le, opcWrGlobal), tmp, s.position)
|
||||
@@ -903,9 +905,17 @@ proc importcSym(c: PCtx; info: TLineInfo; s: PSym) =
|
||||
localError(info, errGenerated,
|
||||
"cannot 'importc' variable at compile time")
|
||||
|
||||
proc cannotEval(n: PNode) {.noinline.} =
|
||||
globalError(n.info, errGenerated, "cannot evaluate at compile time: " &
|
||||
n.renderTree)
|
||||
|
||||
proc genRdVar(c: PCtx; n: PNode; dest: var TDest) =
|
||||
let s = n.sym
|
||||
if sfGlobal in s.flags:
|
||||
if s.isGlobal:
|
||||
if sfCompileTime in s.flags or c.mode == emRepl:
|
||||
discard
|
||||
else:
|
||||
cannotEval(n)
|
||||
if dest < 0: dest = c.getTemp(s.typ)
|
||||
if s.position == 0:
|
||||
if sfImportc in s.flags: c.importcSym(n.info, s)
|
||||
@@ -922,7 +932,9 @@ proc genRdVar(c: PCtx; n: PNode; dest: var TDest) =
|
||||
# we need to generate an assignment:
|
||||
genAsgn(c, dest, n, c.prc.slots[dest].kind >= slotSomeTemp)
|
||||
else:
|
||||
InternalError(n.info, s.name.s & " " & $s.position)
|
||||
# see tests/t99bott for an example that triggers it:
|
||||
cannotEval(n)
|
||||
#InternalError(n.info, s.name.s & " " & $s.position)
|
||||
|
||||
proc genAccess(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode) =
|
||||
let a = c.genx(n.sons[0])
|
||||
@@ -1022,7 +1034,7 @@ proc genVarSection(c: PCtx; n: PNode) =
|
||||
c.freeTemp(tmp)
|
||||
elif a.sons[0].kind == nkSym:
|
||||
let s = a.sons[0].sym
|
||||
if sfGlobal in s.flags:
|
||||
if s.isGlobal:
|
||||
if s.position == 0:
|
||||
if sfImportc in s.flags: c.importcSym(a.info, s)
|
||||
else:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
discard """
|
||||
file: "t99bott.nim"
|
||||
line: 26
|
||||
errormsg: "constant expression expected"
|
||||
errormsg: "cannot evaluate at compile time: bn"
|
||||
disabled: false
|
||||
"""
|
||||
## 99 Bottles of Beer
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
discard """
|
||||
file: "tbind2.nim"
|
||||
line: 12
|
||||
line: 14
|
||||
errormsg: "ambiguous call"
|
||||
"""
|
||||
# Test the new ``bind`` keyword for templates
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
discard """
|
||||
line: 24
|
||||
errormsg: "usage of 'disallowIf' is a user-defined error"
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
template optZero{x+x}(x: int): int = x*3
|
||||
@@ -25,4 +26,4 @@ if s[0] != "hi":
|
||||
echo "do it"
|
||||
echo "more branches"
|
||||
else:
|
||||
nil
|
||||
discard
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
discard """
|
||||
line: 1804
|
||||
line: 1840
|
||||
file: "system.nim"
|
||||
errormsg: "can raise an unlisted exception: ref EIO"
|
||||
"""
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
discard """
|
||||
file: "system.nim"
|
||||
line: 696
|
||||
file: "tenummix.nim"
|
||||
line: 11
|
||||
errormsg: "type mismatch"
|
||||
"""
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
discard """
|
||||
file: "system.nim"
|
||||
file: "tnot.nim"
|
||||
line: 14
|
||||
errormsg: "type mismatch"
|
||||
"""
|
||||
# BUG: following compiles, but should not:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
discard """
|
||||
output: "Error: constant expression expected"
|
||||
line: 7
|
||||
output: "Error: cannot evaluate at compile time: x"
|
||||
line: 10
|
||||
"""
|
||||
|
||||
var x: array[100, char]
|
||||
|
||||
Reference in New Issue
Block a user