range/case fixes (#11264)

This commit is contained in:
Jasper Jenkins 2019-05-16 07:36:40 -07:00 • committed by Andreas Rumpf
commit 90ed904c4d
4 changed files with 28 additions and 6 deletions

View file

@ -878,10 +878,14 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags): PNode =
var covered: BiggestInt = 0
var typ = commonTypeBegin
var hasElse = false
let caseTyp = skipTypes(n.sons[0].typ, abstractVarRange-{tyTypeDesc})
let caseTyp = skipTypes(n.sons[0].typ, abstractVar-{tyTypeDesc})
const shouldChckCovered = {tyInt..tyInt64, tyChar, tyEnum, tyUInt..tyUInt32, tyBool}
case caseTyp.kind
of tyInt..tyInt64, tyChar, tyEnum, tyUInt..tyUInt32, tyBool:
of shouldChckCovered:
chckCovered = true
of tyRange:
if skipTypes(caseTyp.sons[0], abstractInst).kind in shouldChckCovered:
chckCovered = true
of tyFloat..tyFloat128, tyString, tyError:
discard
else:
@ -889,7 +893,7 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags): PNode =
result = handleCaseStmtMacro(c, n)
if result != nil: return result
localError(c.config, n.info, errSelectorMustBeOfCertainTypes)
localError(c.config, n.sons[0].info, errSelectorMustBeOfCertainTypes)
return
for i in 1 ..< sonsLen(n):
var x = n.sons[i]