mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-27 09:43:58 +00:00
deprecated string case statements without 'else'
This commit is contained in:
@@ -262,13 +262,11 @@ given *slicelist* the ``else`` part is executed. If there is no ``else``
|
||||
part and not all possible values that ``expr`` can hold occur in a
|
||||
``slicelist``, a static error occurs. This holds only for expressions of
|
||||
ordinal types. "All possible values" of ``expr`` are determined by ``expr``'s
|
||||
type.
|
||||
type. To suppress the static error an ``else`` part with an
|
||||
empty ``discard`` statement should be used.
|
||||
|
||||
If the expression is not of an ordinal type, and no ``else`` part is
|
||||
given, control passes after the ``case`` statement.
|
||||
|
||||
To suppress the static error in the ordinal case an ``else`` part with an
|
||||
empty ``discard`` statement can be used.
|
||||
For non ordinal types it is not possible to list every possible value and so
|
||||
these always require an ``else`` part.
|
||||
|
||||
As a special semantic extension, an expression in an ``of`` branch of a case
|
||||
statement may evaluate to a set or array constructor; the set or array is then
|
||||
|
||||
@@ -312,7 +312,7 @@ the compiler that for every other value nothing should be done:
|
||||
The empty `discard statement`_ is a *do nothing* statement. The compiler knows
|
||||
that a case statement with an else part cannot fail and thus the error
|
||||
disappears. Note that it is impossible to cover all possible string values:
|
||||
that is why there is no such check for string cases.
|
||||
that is why string cases always need an ``else`` branch.
|
||||
|
||||
In general the case statement is used for subrange types or enumerations where
|
||||
it is of great help that the compiler checks that you covered any possible
|
||||
|
||||
Reference in New Issue
Block a user