* fixes #14126 [backport:1.2] * used more logic to optimize it further; updated Nimble version
This commit is contained in:
parent
b35d370d88
commit
16003bffe1
3 changed files with 70 additions and 9 deletions
|
|
@ -3,7 +3,10 @@ discard """
|
|||
obj.inner.id = 7
|
||||
id = 7
|
||||
obj = (inner: (kind: Just, id: 7))
|
||||
2'''
|
||||
2
|
||||
(a: "1", b: "2", c: "3")
|
||||
caught
|
||||
(a: "1", b: "", c: "3")'''
|
||||
"""
|
||||
|
||||
# bug #6960
|
||||
|
|
@ -129,12 +132,51 @@ import macros
|
|||
func myfunc(obj: MyObject): MyResult {.raises: [].} =
|
||||
template index: auto =
|
||||
case obj.kind:
|
||||
of Float: $obj.index
|
||||
of Float: $obj.index
|
||||
of Fixed: "Fixed"
|
||||
macro to_str(a: untyped): string =
|
||||
result = newStrLitNode(a.repr)
|
||||
result = newStrLitNode(a.repr)
|
||||
result.val[0] = index
|
||||
result.val[1] = to_str(obj.kind + Ola)
|
||||
|
||||
let x = MyObject(someInt: 10, kind: Fixed)
|
||||
echo myfunc(x).val.len
|
||||
|
||||
# bug #14126
|
||||
|
||||
type X = object
|
||||
a, b, c: string
|
||||
|
||||
proc f(): X =
|
||||
result.a = "a"
|
||||
result.b = "b"
|
||||
raise (ref ValueError)()
|
||||
|
||||
proc ohmanNoNRVO =
|
||||
var x: X
|
||||
x.a = "1"
|
||||
x.b = "2"
|
||||
x.c = "3"
|
||||
|
||||
try:
|
||||
x = f()
|
||||
except:
|
||||
discard
|
||||
|
||||
echo x
|
||||
doAssert x.c == "3", "shouldn't modify x if f raises"
|
||||
|
||||
ohmanNoNRVO()
|
||||
|
||||
proc ohmanNoNRVO2(x: var X) =
|
||||
x.a = "1"
|
||||
x.c = "3"
|
||||
x = f()
|
||||
|
||||
var xgg: X
|
||||
try:
|
||||
ohmanNoNRVO2(xgg)
|
||||
except:
|
||||
echo "caught"
|
||||
echo xgg
|
||||
doAssert xgg.c == "3", "this assert will fail"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue