Make unreachable else in case statements a warning instead of an error (#14190)
* Fix #14019 by making trailing else a warning * Rename to UnreachableElse
This commit is contained in:
parent
1f1e4de3bc
commit
83547ec769
3 changed files with 5 additions and 4 deletions
|
|
@ -39,7 +39,7 @@ type
|
||||||
warnEachIdentIsTuple,
|
warnEachIdentIsTuple,
|
||||||
warnUnsafeSetLen,
|
warnUnsafeSetLen,
|
||||||
warnUnsafeDefault,
|
warnUnsafeDefault,
|
||||||
warnProveInit, warnProveField, warnProveIndex,
|
warnProveInit, warnProveField, warnProveIndex, warnUnreachableElse,
|
||||||
warnStaticIndexCheck, warnGcUnsafe, warnGcUnsafe2,
|
warnStaticIndexCheck, warnGcUnsafe, warnGcUnsafe2,
|
||||||
warnUninit, warnGcMem, warnDestructor, warnLockLevel, warnResultShadowed,
|
warnUninit, warnGcMem, warnDestructor, warnLockLevel, warnResultShadowed,
|
||||||
warnInconsistentSpacing, warnCaseTransition, warnCycleCreated, warnUser,
|
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.",
|
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",
|
warnProveField: "cannot prove that field '$1' is accessible",
|
||||||
warnProveIndex: "cannot prove index '$1' is valid",
|
warnProveIndex: "cannot prove index '$1' is valid",
|
||||||
|
warnUnreachableElse: "unreachable else, all cases are already covered",
|
||||||
warnStaticIndexCheck: "$1",
|
warnStaticIndexCheck: "$1",
|
||||||
warnGcUnsafe: "not GC-safe: '$1'",
|
warnGcUnsafe: "not GC-safe: '$1'",
|
||||||
warnGcUnsafe2: "$1",
|
warnGcUnsafe2: "$1",
|
||||||
|
|
@ -153,7 +154,7 @@ const
|
||||||
"UnsafeCode", "UnusedImport", "InheritFromException",
|
"UnsafeCode", "UnusedImport", "InheritFromException",
|
||||||
"EachIdentIsTuple",
|
"EachIdentIsTuple",
|
||||||
"UnsafeSetLen", "UnsafeDefault",
|
"UnsafeSetLen", "UnsafeDefault",
|
||||||
"ProveInit", "ProveField", "ProveIndex",
|
"ProveInit", "ProveField", "ProveIndex", "UnreachableElse",
|
||||||
"IndexCheck", "GcUnsafe", "GcUnsafe2", "Uninit",
|
"IndexCheck", "GcUnsafe", "GcUnsafe2", "Uninit",
|
||||||
"GcMem", "Destructor", "LockLevel", "ResultShadowed",
|
"GcMem", "Destructor", "LockLevel", "ResultShadowed",
|
||||||
"Spacing", "CaseTransition", "CycleCreated", "User"]
|
"Spacing", "CaseTransition", "CycleCreated", "User"]
|
||||||
|
|
|
||||||
|
|
@ -998,7 +998,7 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags): PNode =
|
||||||
x[0] = semExprBranchScope(c, x[0])
|
x[0] = semExprBranchScope(c, x[0])
|
||||||
typ = commonType(typ, x[0])
|
typ = commonType(typ, x[0])
|
||||||
if (chckCovered and covered == toCover(c, n[0].typ)) or hasElse:
|
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
|
hasElse = true
|
||||||
chckCovered = false
|
chckCovered = false
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -695,7 +695,7 @@ proc semRecordCase(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
||||||
of nkElse:
|
of nkElse:
|
||||||
checkSonsLen(b, 1, c.config)
|
checkSonsLen(b, 1, c.config)
|
||||||
if chckCovered and covered == toCover(c, a[0].typ):
|
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
|
chckCovered = false
|
||||||
else: illFormedAst(n, c.config)
|
else: illFormedAst(n, c.config)
|
||||||
delSon(b, b.len - 1)
|
delSon(b, b.len - 1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue