fixes #1343
This commit is contained in:
parent
f70b35b3b7
commit
ae681be629
3 changed files with 21 additions and 5 deletions
|
|
@ -1118,10 +1118,9 @@ proc checkCanEval(c: PCtx; n: PNode) =
|
||||||
# we need to ensure that we don't evaluate 'x' here:
|
# we need to ensure that we don't evaluate 'x' here:
|
||||||
# proc foo() = var x ...
|
# proc foo() = var x ...
|
||||||
let s = n.sym
|
let s = n.sym
|
||||||
if s.position == 0:
|
if s.kind in {skVar, skTemp, skLet, skParam, skResult} and
|
||||||
if s.kind in {skVar, skTemp, skLet, skParam, skResult} and
|
not s.isOwnedBy(c.prc.sym) and s.owner != c.module:
|
||||||
not s.isOwnedBy(c.prc.sym) and s.owner != c.module:
|
cannotEval(n)
|
||||||
cannotEval(n)
|
|
||||||
|
|
||||||
proc isTemp(c: PCtx; dest: TDest): bool =
|
proc isTemp(c: PCtx; dest: TDest): bool =
|
||||||
result = dest >= 0 and c.prc.slots[dest].kind >= slotTempUnknown
|
result = dest >= 0 and c.prc.slots[dest].kind >= slotTempUnknown
|
||||||
|
|
|
||||||
17
tests/vm/twrongarray.nim
Normal file
17
tests/vm/twrongarray.nim
Normal file
|
|
@ -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
|
||||||
|
|
@ -4,6 +4,6 @@ discard """
|
||||||
"""
|
"""
|
||||||
|
|
||||||
var x: array[100, char]
|
var x: array[100, char]
|
||||||
template Foo : expr = x[42]
|
template foo : expr = x[42]
|
||||||
|
|
||||||
const myConst = foo
|
const myConst = foo
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue