Consider range type of runtime discrim [feature] (#11432)

This commit is contained in:
Oscar Nihlgård
2019-08-20 17:39:49 +02:00
committed by Andreas Rumpf
parent d00c8febee
commit 4264e9576d
3 changed files with 99 additions and 17 deletions

View File

@@ -1600,7 +1600,9 @@ statement. If possible values of the discriminator variable in a
``case`` statement branch are a subset of discriminator values for the selected
object branch, the initialization is considered valid. This analysis only works
for immutable discriminators of an ordinal type and disregards ``elif``
branches.
branches. For discriminator values with a ``range`` type, the compiler
checks if the entire range of possible values for the discriminator value is
valid for the choosen object branch.
A small example:
@@ -1619,6 +1621,10 @@ A small example:
else:
echo "ignoring: ", unknownKind
# also valid, since unknownKindBounded can only contain the values nkAdd or nkSub
let unknownKindBounded = range[nkAdd..nkSub](unknownKind)
z = Node(kind: unknownKindBounded, leftOp: Node(), rightOp: Node())
Set type
--------