From c1155cd2a523c62da40d581a6ac79c6bca771fb0 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 2 Jul 2013 19:32:12 +0200 Subject: [PATCH] fixes #503 --- compiler/sem.nim | 22 ++++++++++++---------- tests/reject/twrongconst.nim | 10 ++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 tests/reject/twrongconst.nim diff --git a/compiler/sem.nim b/compiler/sem.nim index bcdfc7939d..4396a90931 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -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 diff --git a/tests/reject/twrongconst.nim b/tests/reject/twrongconst.nim new file mode 100644 index 0000000000..16fe3bff65 --- /dev/null +++ b/tests/reject/twrongconst.nim @@ -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