mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 03:32:32 +00:00
fixes #503
This commit is contained in:
@@ -141,21 +141,23 @@ proc semDirectOp(c: PContext, n: PNode, flags: TExprFlags): 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 =
|
||||
var e = semExprWithType(c, n)
|
||||
if e == nil:
|
||||
LocalError(n.info, errConstExprExpected)
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user