diff options
author | Araq <rumpf_a@web.de> | 2013-12-05 11:28:45 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-12-05 11:28:45 +0100 |
commit | 3560827a287a6a363b810b881133e80464db15c6 (patch) | |
tree | f8f70ad7f4c3c3ebb5fbb51fcf9e32613aa592fa | |
parent | c0a3d44060c2c16c11be1244340f79742a2732cb (diff) | |
download | Nim-3560827a287a6a363b810b881133e80464db15c6.tar.gz |
makes 'reject' tests green
-rw-r--r-- | compiler/vmgen.nim | 20 | ||||
-rw-r--r-- | tests/reject/t99bott.nim | 2 | ||||
-rw-r--r-- | tests/reject/tbind2.nim | 2 | ||||
-rw-r--r-- | tests/reject/tdisallowif.nim | 3 | ||||
-rw-r--r-- | tests/reject/teffects1.nim | 2 | ||||
-rw-r--r-- | tests/reject/tenummix.nim | 4 | ||||
-rw-r--r-- | tests/reject/tnot.nim | 3 | ||||
-rw-r--r-- | tests/reject/twrongconst.nim | 4 |
8 files changed, 27 insertions, 13 deletions
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 46edad2cd..cc395f6c5 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 7ebfd61e9..d18cb0d5c 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 72a9844bb..e8e21ad02 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 10f54288a..18dfd1c82 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 1c6c4bed8..f5eb56dc8 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 f58e7989d..aaf0be2cb 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 1985ef666..cd0f538e6 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 16fe3bff6..e5b8a15bd 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] |