summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorClyybber <darkmine956@gmail.com>2020-05-02 16:09:02 +0200
committerGitHub <noreply@github.com>2020-05-02 16:09:02 +0200
commit83547ec769d9c55b47a8d7a9e3cfc79aab09f977 (patch)
treec29b44462ef76a7d26d20b6ca2ea2bb573f32e0a /compiler
parent1f1e4de3bc45382ef6674706ef5292bd3c8215a1 (diff)
downloadNim-83547ec769d9c55b47a8d7a9e3cfc79aab09f977.tar.gz
Make unreachable else in case statements a warning instead of an error (#14190)
* Fix #14019 by making trailing else a warning

* Rename to UnreachableElse
Diffstat (limited to 'compiler')
-rw-r--r--compiler/lineinfos.nim5
-rw-r--r--compiler/semstmts.nim2
-rw-r--r--compiler/semtypes.nim2
3 files changed, 5 insertions, 4 deletions
diff --git a/compiler/lineinfos.nim b/compiler/lineinfos.nim
index 9c10105b1..eea55defc 100644
--- a/compiler/lineinfos.nim
+++ b/compiler/lineinfos.nim
@@ -39,7 +39,7 @@ type
     warnEachIdentIsTuple,
     warnUnsafeSetLen,
     warnUnsafeDefault,
-    warnProveInit, warnProveField, warnProveIndex,
+    warnProveInit, warnProveField, warnProveIndex, warnUnreachableElse,
     warnStaticIndexCheck, warnGcUnsafe, warnGcUnsafe2,
     warnUninit, warnGcMem, warnDestructor, warnLockLevel, warnResultShadowed,
     warnInconsistentSpacing, warnCaseTransition, warnCycleCreated, warnUser,
@@ -96,6 +96,7 @@ const
     warnProveInit: "Cannot prove that '$1' is initialized. This will become a compile time error in the future.",
     warnProveField: "cannot prove that field '$1' is accessible",
     warnProveIndex: "cannot prove index '$1' is valid",
+    warnUnreachableElse: "unreachable else, all cases are already covered",
     warnStaticIndexCheck: "$1",
     warnGcUnsafe: "not GC-safe: '$1'",
     warnGcUnsafe2: "$1",
@@ -153,7 +154,7 @@ const
     "UnsafeCode", "UnusedImport", "InheritFromException",
     "EachIdentIsTuple",
     "UnsafeSetLen", "UnsafeDefault",
-    "ProveInit", "ProveField", "ProveIndex",
+    "ProveInit", "ProveField", "ProveIndex", "UnreachableElse",
     "IndexCheck", "GcUnsafe", "GcUnsafe2", "Uninit",
     "GcMem", "Destructor", "LockLevel", "ResultShadowed",
     "Spacing", "CaseTransition", "CycleCreated", "User"]
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 6ebe5723e..22055a33d 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -998,7 +998,7 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags): PNode =
       x[0] = semExprBranchScope(c, x[0])
       typ = commonType(typ, x[0])
       if (chckCovered and covered == toCover(c, n[0].typ)) or hasElse:
-        localError(c.config, x.info, "invalid else, all cases are already covered")
+        message(c.config, x.info, warnUnreachableElse)
       hasElse = true
       chckCovered = false
     else:
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index e6cbe56e8..a069fba60 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -695,7 +695,7 @@ proc semRecordCase(c: PContext, n: PNode, check: var IntSet, pos: var int,
     of nkElse:
       checkSonsLen(b, 1, c.config)
       if chckCovered and covered == toCover(c, a[0].typ):
-        localError(c.config, b.info, "invalid else, all cases are already covered")
+        message(c.config, b.info, warnUnreachableElse)
       chckCovered = false
     else: illFormedAst(n, c.config)
     delSon(b, b.len - 1)