fix bool and range (#11336)
This commit is contained in:
parent
f774426095
commit
1286ba3452
1 changed files with 6 additions and 4 deletions
|
|
@ -95,7 +95,8 @@ template processBranchVals(b, op) =
|
||||||
|
|
||||||
proc allPossibleValues(c: PContext, t: PType): IntSet =
|
proc allPossibleValues(c: PContext, t: PType): IntSet =
|
||||||
result = initIntSet()
|
result = initIntSet()
|
||||||
if t.kind == tyEnum:
|
if t.enumHasHoles:
|
||||||
|
let t = t.skipTypes(abstractRange)
|
||||||
for field in t.n.sons:
|
for field in t.n.sons:
|
||||||
result.incl(field.sym.position)
|
result.incl(field.sym.position)
|
||||||
else:
|
else:
|
||||||
|
|
@ -112,10 +113,11 @@ proc branchVals(c: PContext, caseNode: PNode, caseIdx: int,
|
||||||
for i in 1 .. caseNode.len-2:
|
for i in 1 .. caseNode.len-2:
|
||||||
processBranchVals(caseNode[i], excl)
|
processBranchVals(caseNode[i], excl)
|
||||||
|
|
||||||
proc formatUnsafeBranchVals(c: PContext, t: PType, diffVals: IntSet): string =
|
proc formatUnsafeBranchVals(t: PType, diffVals: IntSet): string =
|
||||||
if diffVals.len <= 32:
|
if diffVals.len <= 32:
|
||||||
var strs: seq[string]
|
var strs: seq[string]
|
||||||
if t.kind == tyEnum:
|
let t = t.skipTypes(abstractRange)
|
||||||
|
if t.kind in {tyEnum, tyBool}:
|
||||||
var i = 0
|
var i = 0
|
||||||
for val in diffVals:
|
for val in diffVals:
|
||||||
while t.n.sons[i].sym.position < val: inc(i)
|
while t.n.sons[i].sym.position < val: inc(i)
|
||||||
|
|
@ -272,7 +274,7 @@ proc semConstructFields(c: PContext, recNode: PNode,
|
||||||
localError(c.config, discriminatorVal.info, ("possible values " &
|
localError(c.config, discriminatorVal.info, ("possible values " &
|
||||||
"$2are in conflict with discriminator values for " &
|
"$2are in conflict with discriminator values for " &
|
||||||
"selected object branch $1.") % [$selectedBranch,
|
"selected object branch $1.") % [$selectedBranch,
|
||||||
formatUnsafeBranchVals(c, recNode.sons[0].typ, branchValsDiff)])
|
formatUnsafeBranchVals(recNode.sons[0].typ, branchValsDiff)])
|
||||||
else:
|
else:
|
||||||
if branchNode.kind != nkElse:
|
if branchNode.kind != nkElse:
|
||||||
if not branchNode.caseBranchMatchesExpr(discriminatorVal):
|
if not branchNode.caseBranchMatchesExpr(discriminatorVal):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue