implements #1332
This commit is contained in:
parent
21be7bf85a
commit
f9d7e8db2a
2 changed files with 6 additions and 6 deletions
|
|
@ -443,14 +443,14 @@ proc semCaseBranch(c: PContext, t, branch: PNode, branchIndex: int,
|
||||||
elif isRange(b):
|
elif isRange(b):
|
||||||
branch.sons[i] = semCaseBranchRange(c, t, b, covered)
|
branch.sons[i] = semCaseBranchRange(c, t, b, covered)
|
||||||
else:
|
else:
|
||||||
|
# constant sets and arrays are allowed:
|
||||||
var r = semConstExpr(c, b)
|
var r = semConstExpr(c, b)
|
||||||
# for ``{}`` we want to trigger the type mismatch in ``fitNode``:
|
# for ``{}`` we want to trigger the type mismatch in ``fitNode``:
|
||||||
if r.kind != nkCurly or len(r) == 0:
|
if r.kind notin {nkCurly, nkBracket} or len(r) == 0:
|
||||||
checkMinSonsLen(t, 1)
|
checkMinSonsLen(t, 1)
|
||||||
branch.sons[i] = skipConv(fitNode(c, t.sons[0].typ, r))
|
branch.sons[i] = skipConv(fitNode(c, t.sons[0].typ, r))
|
||||||
inc(covered)
|
inc(covered)
|
||||||
else:
|
else:
|
||||||
# constant sets have special rules
|
|
||||||
# first element is special and will overwrite: branch.sons[i]:
|
# first element is special and will overwrite: branch.sons[i]:
|
||||||
branch.sons[i] = semCaseBranchSetElem(c, t, r[0], covered)
|
branch.sons[i] = semCaseBranchSetElem(c, t, r[0], covered)
|
||||||
# other elements have to be added to ``branch``
|
# other elements have to be added to ``branch``
|
||||||
|
|
|
||||||
|
|
@ -2228,12 +2228,12 @@ type.
|
||||||
If the expression is not of an ordinal type, and no ``else`` part is
|
If the expression is not of an ordinal type, and no ``else`` part is
|
||||||
given, control passes after the ``case`` statement.
|
given, control passes after the ``case`` statement.
|
||||||
|
|
||||||
To suppress the static error in the ordinal case an ``else`` part with a ``nil``
|
To suppress the static error in the ordinal case an ``else`` part with an
|
||||||
statement can be used.
|
empty ``discard`` statement can be used.
|
||||||
|
|
||||||
As a special semantic extension, an expression in an ``of`` branch of a case
|
As a special semantic extension, an expression in an ``of`` branch of a case
|
||||||
statement may evaluate to a set constructor; the set is then expanded into
|
statement may evaluate to a set or array constructor; the set or array is then
|
||||||
a list of its elements:
|
expanded into a list of its elements:
|
||||||
|
|
||||||
.. code-block:: nimrod
|
.. code-block:: nimrod
|
||||||
const
|
const
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue