From 3560827a287a6a363b810b881133e80464db15c6 Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 5 Dec 2013 11:28:45 +0100 Subject: [PATCH] makes 'reject' tests green --- compiler/vmgen.nim | 20 ++++++++++++++++---- tests/reject/t99bott.nim | 2 +- tests/reject/tbind2.nim | 2 +- tests/reject/tdisallowif.nim | 3 ++- tests/reject/teffects1.nim | 2 +- tests/reject/tenummix.nim | 4 ++-- tests/reject/tnot.nim | 3 ++- tests/reject/twrongconst.nim | 4 ++-- 8 files changed, 27 insertions(+), 13 deletions(-) diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 46edad2cdc..cc395f6c57 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -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: diff --git a/tests/reject/t99bott.nim b/tests/reject/t99bott.nim index 7ebfd61e9c..d18cb0d5c7 100644 --- a/tests/reject/t99bott.nim +++ b/tests/reject/t99bott.nim @@ -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 diff --git a/tests/reject/tbind2.nim b/tests/reject/tbind2.nim index 72a9844bb2..e8e21ad024 100644 --- a/tests/reject/tbind2.nim +++ b/tests/reject/tbind2.nim @@ -1,6 +1,6 @@ discard """ file: "tbind2.nim" - line: 12 + line: 14 errormsg: "ambiguous call" """ # Test the new ``bind`` keyword for templates diff --git a/tests/reject/tdisallowif.nim b/tests/reject/tdisallowif.nim index 10f54288a8..18dfd1c826 100644 --- a/tests/reject/tdisallowif.nim +++ b/tests/reject/tdisallowif.nim @@ -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 diff --git a/tests/reject/teffects1.nim b/tests/reject/teffects1.nim index 1c6c4bed8a..f5eb56dc80 100644 --- a/tests/reject/teffects1.nim +++ b/tests/reject/teffects1.nim @@ -1,5 +1,5 @@ discard """ - line: 1804 + line: 1840 file: "system.nim" errormsg: "can raise an unlisted exception: ref EIO" """ diff --git a/tests/reject/tenummix.nim b/tests/reject/tenummix.nim index f58e7989de..aaf0be2cb4 100644 --- a/tests/reject/tenummix.nim +++ b/tests/reject/tenummix.nim @@ -1,6 +1,6 @@ discard """ - file: "system.nim" - line: 696 + file: "tenummix.nim" + line: 11 errormsg: "type mismatch" """ diff --git a/tests/reject/tnot.nim b/tests/reject/tnot.nim index 1985ef6667..cd0f538e62 100644 --- a/tests/reject/tnot.nim +++ b/tests/reject/tnot.nim @@ -1,5 +1,6 @@ discard """ - file: "system.nim" + file: "tnot.nim" + line: 14 errormsg: "type mismatch" """ # BUG: following compiles, but should not: diff --git a/tests/reject/twrongconst.nim b/tests/reject/twrongconst.nim index 16fe3bff65..e5b8a15bd0 100644 --- a/tests/reject/twrongconst.nim +++ b/tests/reject/twrongconst.nim @@ -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]