warn about observerable stores but don't prevent them for 1.2.2 [backport:1.2]; refs https://github.com/nim-lang/RFCs/issues/230 (#14510)

This commit is contained in:
Andreas Rumpf 2020-05-30 19:38:51 +02:00 • committed by GitHub
commit 52c3633223
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 8 deletions

View file

@ -43,8 +43,9 @@ proc preventNrvo(p: BProc; le, ri: PNode): bool =
for i in 1..<ri.len: for i in 1..<ri.len:
let r = ri[i] let r = ri[i]
if isPartOf(le, r) != arNo: return true if isPartOf(le, r) != arNo: return true
return canRaiseDisp(p, ri[0]) and if canRaiseDisp(p, ri[0]) and
(p.nestedTryStmts.len > 0 or locationEscapes(p, le)) (p.nestedTryStmts.len > 0 or locationEscapes(p, le)):
message(p.config, le.info, warnObservableStores, $le)
proc hasNoInit(call: PNode): bool {.inline.} = proc hasNoInit(call: PNode): bool {.inline.} =
result = call[0].kind == nkSym and sfNoInit in call[0].sym.flags result = call[0].kind == nkSym and sfNoInit in call[0].sym.flags

View file

@ -52,7 +52,9 @@ type
warnProveInit, warnProveField, warnProveIndex, warnUnreachableElse, 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,
warnObservableStores,
warnUser,
hintSuccess, hintSuccessX, hintCC, hintSuccess, hintSuccessX, hintCC,
hintLineTooLong, hintXDeclaredButNotUsed, hintLineTooLong, hintXDeclaredButNotUsed,
hintConvToBaseNotNeeded, hintConvToBaseNotNeeded,
@ -119,6 +121,7 @@ const
warnInconsistentSpacing: "Number of spaces around '$#' is not consistent", warnInconsistentSpacing: "Number of spaces around '$#' is not consistent",
warnCaseTransition: "Potential object case transition, instantiate new object instead", warnCaseTransition: "Potential object case transition, instantiate new object instead",
warnCycleCreated: "$1", warnCycleCreated: "$1",
warnObservableStores: "observable stores to '$1'",
warnUser: "$1", warnUser: "$1",
hintSuccess: "operation successful: $#", hintSuccess: "operation successful: $#",
# keep in sync with `testament.isSuccess` # keep in sync with `testament.isSuccess`
@ -169,7 +172,8 @@ const
"ProveInit", "ProveField", "ProveIndex", "UnreachableElse", "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",
"ObservableStores", "User"]
HintsToStr* = [ HintsToStr* = [
"Success", "SuccessX", "CC", "LineTooLong", "Success", "SuccessX", "CC", "LineTooLong",

View file

@ -4,9 +4,9 @@ obj.inner.id = 7
id = 7 id = 7
obj = (inner: (kind: Just, id: 7)) obj = (inner: (kind: Just, id: 7))
2 2
(a: "1", b: "2", c: "3") (a: "a", b: "b", c: "")
caught caught
(a: "1", b: "", c: "3")''' (a: "a", b: "b", c: "")'''
""" """
# bug #6960 # bug #6960
@ -164,7 +164,8 @@ proc ohmanNoNRVO =
discard discard
echo x echo x
doAssert x.c == "3", "shouldn't modify x if f raises" # once NVRO is sorted out, x.c == "3"
doAssert x.c == "", "shouldn't modify x if f raises"
ohmanNoNRVO() ohmanNoNRVO()
@ -179,4 +180,5 @@ try:
except: except:
echo "caught" echo "caught"
echo xgg echo xgg
doAssert xgg.c == "3", "this assert will fail" # once NVRO is sorted out, xgg.c == "3"
doAssert xgg.c == "", "this assert will fail"