diff options
author | Araq <rumpf_a@web.de> | 2014-08-15 09:57:03 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-08-15 09:57:03 +0200 |
commit | ae681be62918ea1e766b230e2d098177794469e9 (patch) | |
tree | d5059ffa36875eacdd01620dcdbbe8db28729ad1 | |
parent | f70b35b3b7837028296bcb06120fc293d11c613c (diff) | |
download | Nim-ae681be62918ea1e766b230e2d098177794469e9.tar.gz |
fixes #1343
-rw-r--r-- | compiler/vmgen.nim | 7 | ||||
-rw-r--r-- | tests/vm/twrongarray.nim | 17 | ||||
-rw-r--r-- | tests/vm/twrongconst.nim | 2 |
3 files changed, 21 insertions, 5 deletions
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index adbca8cca..94afbf008 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1118,10 +1118,9 @@ proc checkCanEval(c: PCtx; n: PNode) = # we need to ensure that we don't evaluate 'x' here: # proc foo() = var x ... let s = n.sym - if s.position == 0: - if s.kind in {skVar, skTemp, skLet, skParam, skResult} and - not s.isOwnedBy(c.prc.sym) and s.owner != c.module: - cannotEval(n) + if s.kind in {skVar, skTemp, skLet, skParam, skResult} and + not s.isOwnedBy(c.prc.sym) and s.owner != c.module: + cannotEval(n) proc isTemp(c: PCtx; dest: TDest): bool = result = dest >= 0 and c.prc.slots[dest].kind >= slotTempUnknown diff --git a/tests/vm/twrongarray.nim b/tests/vm/twrongarray.nim new file mode 100644 index 000000000..c1514d0e9 --- /dev/null +++ b/tests/vm/twrongarray.nim @@ -0,0 +1,17 @@ +discard """ + errormsg: "cannot evaluate at compile time: size" + line: 16 +""" + +#bug #1343 + +when false: + proc one(dummy: int, size: int) = + var x: array[size, int] # compile error: constant expression expected + + proc three(size: int) = + var x: array[size * 1, int] # compile error: cannot evaluate at compile time: size + +proc two(dummy: int, size: int) = + var x: array[size * 1, int] # compiles, but shouldn't? + #assert(x.len == size) # just for fun diff --git a/tests/vm/twrongconst.nim b/tests/vm/twrongconst.nim index 5c0c80f9f..68ab2757c 100644 --- a/tests/vm/twrongconst.nim +++ b/tests/vm/twrongconst.nim @@ -4,6 +4,6 @@ discard """ """ var x: array[100, char] -template Foo : expr = x[42] +template foo : expr = x[42] const myConst = foo |