fix typed case range not counting for exhaustiveness (#24136)

fixes #22661

Range expressions in `of` branches in `case` statements start off as
calls to `..` then become `nkRange` when getting typed. For this reason
the compiler leaves `nkRange` alone when type checking the case
statements again, but it still does the exhaustiveness checking for the
entire case statement, and leaving the range alone means it doesn't
count the values of the range for exhaustiveness. So the counting is now
also done on `nkRange` nodes in the same way as when typechecking it the
first time.
This commit is contained in:
metagn
2024-09-19 00:50:58 +03:00
committed by GitHub
parent 00ac961ab1
commit 58cf62451d
2 changed files with 9 additions and 0 deletions

View File

@@ -619,6 +619,8 @@ proc semCaseBranch(c: PContext, n, branch: PNode, branchIndex: int,
var b = branch[i]
if b.kind == nkRange:
branch[i] = b
# same check as in semBranchRange for exhaustiveness
covered = covered + getOrdValue(b[1]) + 1 - getOrdValue(b[0])
elif isRange(b):
branch[i] = semCaseBranchRange(c, n, b, covered)
else:

View File

@@ -0,0 +1,7 @@
block: # issue #22661
template foo(a: typed) =
a
foo:
case false
of false..true: discard