* fixes #15361; better cursor inference
This commit is contained in:
Andreas Rumpf 2020-09-24 15:41:45 +02:00 • committed by GitHub
commit 4ec5cbac0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 196 additions and 45 deletions

View file

@ -0,0 +1,53 @@
discard """
output: '''true
true
true
true
true'''
cmd: "nim c --gc:arc $file"
"""
# bug #15361
type
ErrorNodeKind = enum Branch, Leaf
Error = ref object
case kind: ErrorNodeKind
of Branch:
left: Error
right: Error
of Leaf:
leafError: string
input: string
proc ret(input: string, lefterr, righterr: Error): Error =
result = Error(kind: Branch, left: lefterr, right: righterr, input: input)
proc parser() =
var rerrors: Error
let lerrors = Error(
kind: Leaf,
leafError: "first error",
input: "123 ;"
)
# If you remove "block" - everything works
block:
let rresult = Error(
kind: Leaf,
leafError: "second error",
input: ";"
)
# this assignment is needed too
rerrors = rresult
# Returns Error(kind: Branch, left: lerrors, right: rerrors, input: "some val")
# needs to be a proc call for some reason, can't inline the result
var data = ret(input = "some val", lefterr = lerrors, righterr = rerrors)
echo data.left.leafError == "first error"
echo data.left.input == "123 ;"
# stacktrace shows this line
echo data.right.leafError == "second error"
echo data.right.input == ";"
echo data.input == "some val"
parser()

View file

@ -52,7 +52,7 @@ _ = (
blitTmp, ";")
lvalue = _[0]
lnext_cursor = _[1]
`=sink`(result.value, lvalue)
`=sink`(result.value, move lvalue)
-- end of expandArc ------------------------
--expandArc: tt
@ -148,7 +148,7 @@ proc p1(): Maybe =
var lnext: string
(lvalue, lnext) = (lresult, ";")
result.value = lvalue
result.value = move lvalue
proc tissue15130 =
doAssert p1().value == @[123]

View file

@ -23,17 +23,18 @@ joinable: false
type T = object
proc `=`(lhs: var T, rhs: T) =
echo "assign"
echo "assign"
proc `=destroy`(v: var T) =
echo "destroy"
echo "destroy"
proc use(x: T) = discard
proc usedToBeBlock =
var v1 : T
var v2 : T = v1
use v1
var v1 = T()
var v2: T = v1
discard addr(v2) # prevent cursorfication
use v1
usedToBeBlock()

View file

@ -96,14 +96,16 @@ proc info =
allocCount = 0
deallocCount = 0
proc copy(a: Matrix): Matrix = a
proc test1 =
var a = matrix(5, 5, 1.0)
var b = a
var b = copy a
var c = a + b
proc test2 =
var a = matrix(5, 5, 1.0)
var b = a
var b = copy a
var c = -a
proc test3 =