Skip to content

Commit

Permalink
warn about observerable stores but don't prevent them for 1.2.2 [back…
Browse files Browse the repository at this point in the history
…port:1.2]; refs nim-lang/RFCs#230 (#14510)
  • Loading branch information
Araq authored May 30, 2020
1 parent 7ccc7d7 commit 52c3633
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
5 changes: 3 additions & 2 deletions compiler/ccgcalls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ proc preventNrvo(p: BProc; le, ri: PNode): bool =
for i in 1..<ri.len:
let r = ri[i]
if isPartOf(le, r) != arNo: return true
return canRaiseDisp(p, ri[0]) and
(p.nestedTryStmts.len > 0 or locationEscapes(p, le))
if canRaiseDisp(p, ri[0]) and
(p.nestedTryStmts.len > 0 or locationEscapes(p, le)):
message(p.config, le.info, warnObservableStores, $le)

proc hasNoInit(call: PNode): bool {.inline.} =
result = call[0].kind == nkSym and sfNoInit in call[0].sym.flags
Expand Down
8 changes: 6 additions & 2 deletions compiler/lineinfos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ type
warnProveInit, warnProveField, warnProveIndex, warnUnreachableElse,
warnStaticIndexCheck, warnGcUnsafe, warnGcUnsafe2,
warnUninit, warnGcMem, warnDestructor, warnLockLevel, warnResultShadowed,
warnInconsistentSpacing, warnCaseTransition, warnCycleCreated, warnUser,
warnInconsistentSpacing, warnCaseTransition, warnCycleCreated,
warnObservableStores,
warnUser,
hintSuccess, hintSuccessX, hintCC,
hintLineTooLong, hintXDeclaredButNotUsed,
hintConvToBaseNotNeeded,
Expand Down Expand Up @@ -119,6 +121,7 @@ const
warnInconsistentSpacing: "Number of spaces around '$#' is not consistent",
warnCaseTransition: "Potential object case transition, instantiate new object instead",
warnCycleCreated: "$1",
warnObservableStores: "observable stores to '$1'",
warnUser: "$1",
hintSuccess: "operation successful: $#",
# keep in sync with `testament.isSuccess`
Expand Down Expand Up @@ -169,7 +172,8 @@ const
"ProveInit", "ProveField", "ProveIndex", "UnreachableElse",
"IndexCheck", "GcUnsafe", "GcUnsafe2", "Uninit",
"GcMem", "Destructor", "LockLevel", "ResultShadowed",
"Spacing", "CaseTransition", "CycleCreated", "User"]
"Spacing", "CaseTransition", "CycleCreated",
"ObservableStores", "User"]

HintsToStr* = [
"Success", "SuccessX", "CC", "LineTooLong",
Expand Down
10 changes: 6 additions & 4 deletions tests/ccgbugs/tcodegenbug1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ obj.inner.id = 7
id = 7
obj = (inner: (kind: Just, id: 7))
2
(a: "1", b: "2", c: "3")
(a: "a", b: "b", c: "")
caught
(a: "1", b: "", c: "3")'''
(a: "a", b: "b", c: "")'''
"""

# bug #6960
Expand Down Expand Up @@ -164,7 +164,8 @@ proc ohmanNoNRVO =
discard

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()

Expand All @@ -179,4 +180,5 @@ try:
except:
echo "caught"
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"

0 comments on commit 52c3633

Please sign in to comment.