Allow empty sets in case/of branches.
Added support for conditional compilation using 'when' with empty sets and arrays in 'case of' branches. Please enter the commit message for your changes. Lines starting
This commit is contained in:
parent
7324ed7f1f
commit
79384ea729
2 changed files with 30 additions and 2 deletions
|
|
@ -452,6 +452,7 @@ proc semCaseBranchSetElem(c: PContext, t, b: PNode,
|
|||
|
||||
proc semCaseBranch(c: PContext, t, branch: PNode, branchIndex: int,
|
||||
covered: var BiggestInt) =
|
||||
|
||||
for i in countup(0, sonsLen(branch) - 2):
|
||||
var b = branch.sons[i]
|
||||
if b.kind == nkRange:
|
||||
|
|
@ -461,8 +462,11 @@ proc semCaseBranch(c: PContext, t, branch: PNode, branchIndex: int,
|
|||
else:
|
||||
# constant sets and arrays are allowed:
|
||||
var r = semConstExpr(c, b)
|
||||
# for ``{}`` we want to trigger the type mismatch in ``fitNode``:
|
||||
if r.kind notin {nkCurly, nkBracket} or len(r) == 0:
|
||||
if r.kind in {nkCurly, nkBracket} and len(r) == 0 and sonsLen(branch)==2:
|
||||
# discarding ``{}`` and ``[]`` branches silently
|
||||
delSon(branch, 0)
|
||||
return
|
||||
elif r.kind notin {nkCurly, nkBracket} or len(r) == 0:
|
||||
checkMinSonsLen(t, 1)
|
||||
branch.sons[i] = skipConv(fitNode(c, t.sons[0].typ, r))
|
||||
inc(covered)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue