Skip to content

Commit 6446ee1

Browse files
committed
sem: use proper error propagation in semWhen
Replace `semConstExpr` with `semRealConstExpr`, the latter which returns `nkError` nodes. `semRealConstExpr` was also missing the execution context handling that `semConstExpr` uses.
1 parent 968f973 commit 6446ee1

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

compiler/sem/sem.nim

+2
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,9 @@ proc semRealConstExpr(c: PContext, n: PNode): PNode =
682682
addInNimDebugUtils(c.config, "semRealConstExpr", n, result)
683683
assert not n.isError
684684

685+
pushExecCon(c, {})
685686
result = semExprWithType(c, n)
687+
popExecCon(c)
686688
if result.kind != nkError:
687689
result = evalConstExpr(c, result)
688690

compiler/sem/semexprs.nim

+1-1
Original file line numberDiff line numberDiff line change
@@ -2945,7 +2945,7 @@ proc semWhen(c: PContext, n: PNode, flags: TExprFlags): PNode =
29452945
case it.kind
29462946
of nkElifBranch, nkElifExpr:
29472947
checkSonsLen(it, 2, c.config)
2948-
let e = forceBool(c, semConstExpr(c, it[0]))
2948+
let e = forceBool(c, semRealConstExpr(c, it[0]))
29492949
if e.kind == nkError:
29502950
# error in the condition expression; wrap and return
29512951
result = copyNodeWithKids(n)

0 commit comments

Comments
 (0)