mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-10 05:38:10 +00:00
fix bool and range (#11336)
This commit is contained in:
committed by
Andreas Rumpf
parent
f774426095
commit
1286ba3452
@@ -95,7 +95,8 @@ template processBranchVals(b, op) =
|
||||
|
||||
proc allPossibleValues(c: PContext, t: PType): IntSet =
|
||||
result = initIntSet()
|
||||
if t.kind == tyEnum:
|
||||
if t.enumHasHoles:
|
||||
let t = t.skipTypes(abstractRange)
|
||||
for field in t.n.sons:
|
||||
result.incl(field.sym.position)
|
||||
else:
|
||||
@@ -112,10 +113,11 @@ proc branchVals(c: PContext, caseNode: PNode, caseIdx: int,
|
||||
for i in 1 .. caseNode.len-2:
|
||||
processBranchVals(caseNode[i], excl)
|
||||
|
||||
proc formatUnsafeBranchVals(c: PContext, t: PType, diffVals: IntSet): string =
|
||||
proc formatUnsafeBranchVals(t: PType, diffVals: IntSet): string =
|
||||
if diffVals.len <= 32:
|
||||
var strs: seq[string]
|
||||
if t.kind == tyEnum:
|
||||
let t = t.skipTypes(abstractRange)
|
||||
if t.kind in {tyEnum, tyBool}:
|
||||
var i = 0
|
||||
for val in diffVals:
|
||||
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 " &
|
||||
"$2are in conflict with discriminator values for " &
|
||||
"selected object branch $1.") % [$selectedBranch,
|
||||
formatUnsafeBranchVals(c, recNode.sons[0].typ, branchValsDiff)])
|
||||
formatUnsafeBranchVals(recNode.sons[0].typ, branchValsDiff)])
|
||||
else:
|
||||
if branchNode.kind != nkElse:
|
||||
if not branchNode.caseBranchMatchesExpr(discriminatorVal):
|
||||
|
||||
Reference in New Issue
Block a user