implemented strictCaseObjects (#20608)
* implemented strictCaseObjects * changelog update
This commit is contained in:
parent
4aa67ad7fd
commit
76763f51aa
6 changed files with 80 additions and 8 deletions
|
|
@ -1054,8 +1054,12 @@ proc buildProperFieldCheck(access, check: PNode; o: Operators): PNode =
|
|||
assert check.getMagic == mNot
|
||||
result = buildProperFieldCheck(access, check[1], o).neg(o)
|
||||
|
||||
proc checkFieldAccess*(m: TModel, n: PNode; conf: ConfigRef) =
|
||||
proc checkFieldAccess*(m: TModel, n: PNode; conf: ConfigRef; produceError: bool) =
|
||||
for i in 1..<n.len:
|
||||
let check = buildProperFieldCheck(n[0], n[i], m.g.operators)
|
||||
if check != nil and m.doesImply(check) != impYes:
|
||||
message(conf, n.info, warnProveField, renderTree(n[0])); break
|
||||
if produceError:
|
||||
localError(conf, n.info, "field access outside of valid case branch: " & renderTree(n[0]))
|
||||
else:
|
||||
message(conf, n.info, warnProveField, renderTree(n[0]))
|
||||
break
|
||||
|
|
|
|||
|
|
@ -217,7 +217,8 @@ type
|
|||
strictEffects,
|
||||
unicodeOperators, # deadcode
|
||||
flexibleOptionalParams,
|
||||
strictDefs
|
||||
strictDefs,
|
||||
strictCaseObjects
|
||||
|
||||
LegacyFeature* = enum
|
||||
allowSemcheckedAstModification,
|
||||
|
|
|
|||
|
|
@ -665,7 +665,7 @@ proc trackCase(tracked: PEffects, n: PNode) =
|
|||
let stringCase = n[0].typ != nil and skipTypes(n[0].typ,
|
||||
abstractVarRange-{tyTypeDesc}).kind in {tyFloat..tyFloat128, tyString, tyCstring}
|
||||
let interesting = not stringCase and interestingCaseExpr(n[0]) and
|
||||
tracked.config.hasWarn(warnProveField)
|
||||
(tracked.config.hasWarn(warnProveField) or strictCaseObjects in tracked.c.features)
|
||||
var inter: TIntersection = @[]
|
||||
var toCover = 0
|
||||
for i in 1..<n.len:
|
||||
|
|
@ -1049,8 +1049,8 @@ proc track(tracked: PEffects, n: PNode) =
|
|||
for i in 0..<n.len: track(tracked, n[i])
|
||||
of nkCheckedFieldExpr:
|
||||
track(tracked, n[0])
|
||||
if tracked.config.hasWarn(warnProveField):
|
||||
checkFieldAccess(tracked.guards, n, tracked.config)
|
||||
if tracked.config.hasWarn(warnProveField) or strictCaseObjects in tracked.c.features:
|
||||
checkFieldAccess(tracked.guards, n, tracked.config, strictCaseObjects in tracked.c.features)
|
||||
of nkTryStmt: trackTryStmt(tracked, n)
|
||||
of nkPragma: trackPragmaStmt(tracked, n)
|
||||
of nkAsgn, nkFastAsgn, nkSinkAsgn:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue