Give error when case has an else branch even though all cases are already covered (#9930)
* Give error when case has an else branch even though all cases are already covered. * Don't check for invalid else for type tyFloat..tyFloat128, tyString, tyError * Remove unnecessary else in unittest.nim * Fix sockets.nim
This commit is contained in:
parent
bb85869237
commit
a3c4791e9c
3 changed files with 3 additions and 6 deletions
|
|
@ -807,11 +807,13 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags): PNode =
|
|||
typ = commonType(typ, x.sons[1])
|
||||
closeScope(c)
|
||||
of nkElse:
|
||||
chckCovered = false
|
||||
checkSonsLen(x, 1, c.config)
|
||||
x.sons[0] = semExprBranchScope(c, x.sons[0])
|
||||
typ = commonType(typ, x.sons[0])
|
||||
hasElse = true
|
||||
if chckCovered and covered == toCover(c, n.sons[0].typ):
|
||||
localError(c.config, x.info, "invalid else, all cases are already covered")
|
||||
chckCovered = false
|
||||
else:
|
||||
illFormedAst(x, c.config)
|
||||
if chckCovered:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue