summary refs log tree commit diff stats
path: root/compiler/semstmts.nim
diff options
context:
space:
mode:
authorNeelesh Chandola <neelesh.chandola@outlook.com>2018-12-13 13:38:10 +0530
committerAndreas Rumpf <rumpf_a@web.de>2018-12-13 09:08:10 +0100
commita3c4791e9cde49f44e7261044cc84fa863bc717c (patch)
tree947f02636388a36a3678fe8ea9e50acea50acd34 /compiler/semstmts.nim
parentbb8586923794291ddabd122490fd2ab7ccc71ee0 (diff)
downloadNim-a3c4791e9cde49f44e7261044cc84fa863bc717c.tar.gz
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
Diffstat (limited to 'compiler/semstmts.nim')
-rw-r--r--compiler/semstmts.nim4
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index aec03b492..5be57f614 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -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: