summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorgenotrance <dev@genotrance.com>2019-06-01 23:40:07 -0500
committerAndreas Rumpf <rumpf_a@web.de>2019-06-02 06:40:07 +0200
commit1255b3c8647c2ad4be831698633eaf2f4a38795c (patch)
tree19c6065007c3bd217affd522fb8981660832b19a
parent4a35d2b571190e94e151091535793cd033b589b1 (diff)
downloadNim-1255b3c8647c2ad4be831698633eaf2f4a38795c.tar.gz
Warn about object case transitions at compile time (#11378)
-rw-r--r--compiler/ccgstmts.nim1
-rw-r--r--compiler/lineinfos.nim5
2 files changed, 4 insertions, 2 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim
index eed046afd..5ddf78a76 100644
--- a/compiler/ccgstmts.nim
+++ b/compiler/ccgstmts.nim
@@ -1274,6 +1274,7 @@ proc genAsgn(p: BProc, e: PNode, fastAsgn: bool) =
   else:
     genLineDir(p, e)
     asgnFieldDiscriminant(p, e)
+    message(p.config, e.info, warnCaseTransition)
 
 proc genStmts(p: BProc, t: PNode) =
   var a: TLoc
diff --git a/compiler/lineinfos.nim b/compiler/lineinfos.nim
index b84d8c895..694ae8e94 100644
--- a/compiler/lineinfos.nim
+++ b/compiler/lineinfos.nim
@@ -36,7 +36,7 @@ type
     warnEachIdentIsTuple,
     warnProveInit, warnProveField, warnProveIndex, warnGcUnsafe, warnGcUnsafe2,
     warnUninit, warnGcMem, warnDestructor, warnLockLevel, warnResultShadowed,
-    warnInconsistentSpacing, warnUser,
+    warnInconsistentSpacing, warnCaseTransition, warnUser,
     hintSuccess, hintSuccessX, hintCC,
     hintLineTooLong, hintXDeclaredButNotUsed, hintConvToBaseNotNeeded,
     hintConvFromXtoItselfNotNeeded, hintExprAlwaysX, hintQuitCalled,
@@ -90,6 +90,7 @@ const
     warnLockLevel: "$1",
     warnResultShadowed: "Special variable 'result' is shadowed.",
     warnInconsistentSpacing: "Number of spaces around '$#' is not consistent",
+    warnCaseTransition: "Potential object case transition, instantiate new object instead",
     warnUser: "$1",
     hintSuccess: "operation successful: $#",
     hintSuccessX: "operation successful ($# lines compiled; $# sec total; $#; $#)",
@@ -135,7 +136,7 @@ const
     "UnsafeCode", "EachIdentIsTuple",
     "ProveInit", "ProveField", "ProveIndex", "GcUnsafe", "GcUnsafe2", "Uninit",
     "GcMem", "Destructor", "LockLevel", "ResultShadowed",
-    "Spacing", "User"]
+    "Spacing", "CaseTransition", "User"]
 
   HintsToStr* = [
     "Success", "SuccessX", "CC", "LineTooLong",