aboutsummaryrefslogtreecommitdiff
path: root/test/escape_closure.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2017-02-13 16:00:53 -0800
committerRobert Griesemer <gri@golang.org>2017-02-15 01:33:03 +0000
commit5267ac2732edd1ba4a13773987dff08e8b4a2dde (patch)
treee75fba029f50ffce20fa05525d2349cf7813bf74 /test/escape_closure.go
parent6910756f9b8c7a97b1435ec40b8ebff9655611d7 (diff)
downloadgo-5267ac2732edd1ba4a13773987dff08e8b4a2dde.tar.gz
go-5267ac2732edd1ba4a13773987dff08e8b4a2dde.zip
cmd/compile/internal/syntax: establish principled position information
Until now, the parser set the position for each Node to the position of the first token belonging to that node. For compatibility with the now defunct gc parser, in many places that position information was modified when the gcCompat flag was set (which it was, by default). Furthermore, in some places, position information was not set at all. This change removes the gcCompat flag and all associated code, and sets position information for all nodes in a more principled way, as proposed by mdempsky (see #16943 for details). Specifically, the position of a node may not be at the very beginning of the respective production. For instance for an Operation `a + b`, the position associated with the node is the position of the `+`. Thus, for `a + b + c` we now get different positions for the two additions. This change does not pass toolstash -cmp because position information recorded in export data and pcline tables is different. There are no other functional changes. Added test suite testing the position of all nodes. Fixes #16943. Change-Id: I3fc02bf096bc3b3d7d2fa655dfd4714a1a0eb90c Reviewed-on: https://go-review.googlesource.com/37017 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test/escape_closure.go')
-rw-r--r--test/escape_closure.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/test/escape_closure.go b/test/escape_closure.go
index e9cf776afb..fc35cb59cf 100644
--- a/test/escape_closure.go
+++ b/test/escape_closure.go
@@ -55,9 +55,9 @@ func ClosureCallArgs4() {
func ClosureCallArgs5() {
x := 0 // ERROR "moved to heap: x"
- sink = func(p *int) *int { // ERROR "leaking param: p to result ~r1" "func literal does not escape"
+ sink = func(p *int) *int { // ERROR "leaking param: p to result ~r1" "func literal does not escape" "\(func literal\)\(&x\) escapes to heap"
return p
- }(&x) // ERROR "&x escapes to heap" "\(func literal\)\(&x\) escapes to heap"
+ }(&x) // ERROR "&x escapes to heap"
}
func ClosureCallArgs6() {
@@ -140,10 +140,10 @@ func ClosureCallArgs14() {
func ClosureCallArgs15() {
x := 0 // ERROR "moved to heap: x"
p := &x // ERROR "moved to heap: p" "&x escapes to heap"
- sink = func(p **int) *int { // ERROR "leaking param: p to result ~r1 level=1" "func literal does not escape"
+ sink = func(p **int) *int { // ERROR "leaking param: p to result ~r1 level=1" "func literal does not escape" "\(func literal\)\(&p\) escapes to heap"
return *p
// BAD: p should not escape here
- }(&p) // ERROR "&p escapes to heap" "\(func literal\)\(&p\) escapes to heap"
+ }(&p) // ERROR "&p escapes to heap"
}
func ClosureLeak1(s string) string { // ERROR "ClosureLeak1 s does not escape"