From 1255b3c8647c2ad4be831698633eaf2f4a38795c Mon Sep 17 00:00:00 2001 From: genotrance Date: Sat, 1 Jun 2019 23:40:07 -0500 Subject: [PATCH] Warn about object case transitions at compile time (#11378) --- compiler/ccgstmts.nim | 1 + compiler/lineinfos.nim | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index eed046afd5..5ddf78a769 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 b84d8c895b..694ae8e94b 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",