enforce the condition of a 'when' condition to be of type bool; refs #8603

This commit is contained in:
Andreas Rumpf 2018-08-23 17:54:04 +02:00
commit 361a2d830a

View file

@ -2085,7 +2085,7 @@ proc semWhen(c: PContext, n: PNode, semCheck = true): PNode =
typ = commonType(typ, it.sons[1].typ) typ = commonType(typ, it.sons[1].typ)
result = n # when nimvm is not elimited until codegen result = n # when nimvm is not elimited until codegen
else: else:
var e = semConstExpr(c, it.sons[0]) let e = forceBool(c, semConstExpr(c, it.sons[0]))
if e.kind != nkIntLit: if e.kind != nkIntLit:
# can happen for cascading errors, assume false # can happen for cascading errors, assume false
# InternalError(n.info, "semWhen") # InternalError(n.info, "semWhen")