fixes #503
This commit is contained in:
parent
dfe195a4a1
commit
c1155cd2a5
2 changed files with 22 additions and 10 deletions
|
|
@ -141,21 +141,23 @@ proc semDirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode
|
||||||
|
|
||||||
proc semWhen(c: PContext, n: PNode, semCheck: bool = true): PNode
|
proc semWhen(c: PContext, n: PNode, semCheck: bool = true): PNode
|
||||||
|
|
||||||
proc evalTypedExpr(c: PContext, e: PNode): PNode =
|
|
||||||
result = getConstExpr(c.module, e)
|
|
||||||
if result == nil:
|
|
||||||
result = evalConstExpr(c.module, e)
|
|
||||||
if result == nil or result.kind == nkEmpty:
|
|
||||||
LocalError(e.info, errConstExprExpected)
|
|
||||||
# error correction:
|
|
||||||
result = e
|
|
||||||
|
|
||||||
proc semConstExpr(c: PContext, n: PNode): PNode =
|
proc semConstExpr(c: PContext, n: PNode): PNode =
|
||||||
var e = semExprWithType(c, n)
|
var e = semExprWithType(c, n)
|
||||||
if e == nil:
|
if e == nil:
|
||||||
LocalError(n.info, errConstExprExpected)
|
LocalError(n.info, errConstExprExpected)
|
||||||
return n
|
return n
|
||||||
result = evalTypedExpr(c, e)
|
result = getConstExpr(c.module, e)
|
||||||
|
if result == nil:
|
||||||
|
result = evalConstExpr(c.module, e)
|
||||||
|
if result == nil or result.kind == nkEmpty:
|
||||||
|
if e.info != n.info:
|
||||||
|
pushInfoContext(n.info)
|
||||||
|
LocalError(e.info, errConstExprExpected)
|
||||||
|
popInfoContext()
|
||||||
|
else:
|
||||||
|
LocalError(e.info, errConstExprExpected)
|
||||||
|
# error correction:
|
||||||
|
result = e
|
||||||
|
|
||||||
include hlo, seminst, semcall
|
include hlo, seminst, semcall
|
||||||
|
|
||||||
|
|
|
||||||
10
tests/reject/twrongconst.nim
Normal file
10
tests/reject/twrongconst.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
discard """
|
||||||
|
output: "Error: constant expression expected"
|
||||||
|
line: 7
|
||||||
|
"""
|
||||||
|
|
||||||
|
var x: array[100, char]
|
||||||
|
template Foo : expr = x[42]
|
||||||
|
|
||||||
|
|
||||||
|
const myConst = foo
|
||||||
Loading…
Add table
Add a link
Reference in a new issue