From a3c4791e9cde49f44e7261044cc84fa863bc717c Mon Sep 17 00:00:00 2001 From: Neelesh Chandola Date: Thu, 13 Dec 2018 13:38:10 +0530 Subject: 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 --- compiler/semstmts.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'compiler') 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: -- cgit 1.4.1-2-gfad0