summaryrefslogtreecommitdiff
path: root/test/inline.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-04-11 09:47:13 -0700
committerDan Scales <danscales@google.com>2021-04-14 01:28:16 +0000
commiteb433ed5a2ab13567cd5d7f0413308174750d5dd (patch)
tree46a288276cc027b310388eb3498e07cef9de024e /test/inline.go
parent8dcc071063c0a9f020f0aafd51b7e0a17f0a0746 (diff)
downloadgo-git-eb433ed5a2ab13567cd5d7f0413308174750d5dd.tar.gz
cmd/compile: set types properly for imported funcs with closures
For the new export/import of node types, we were just missing setting the types of the closure variables (which have the same types as the captured variables) and the OCLOSURE node itself (which has the same type as the Func node). Re-enabled inlining of functions with closures. Change-Id: I687149b061f3ffeec3244ff02dc6e946659077a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/308974 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/inline.go')
-rw-r--r--test/inline.go22
1 files changed, 11 insertions, 11 deletions
diff --git a/test/inline.go b/test/inline.go
index b0911056ca..bc23768d01 100644
--- a/test/inline.go
+++ b/test/inline.go
@@ -58,7 +58,7 @@ func _() int { // ERROR "can inline _"
var somethingWrong error
// local closures can be inlined
-func l(x, y int) (int, int, error) {
+func l(x, y int) (int, int, error) { // ERROR "can inline l"
e := func(err error) (int, int, error) { // ERROR "can inline l.func1" "func literal does not escape" "leaking param: err to result"
return 0, 0, err
}
@@ -90,19 +90,19 @@ func n() int {
// make sure assignment inside closure is detected
func o() int {
foo := func() int { return 1 } // ERROR "can inline o.func1" "func literal does not escape"
- func(x int) { // ERROR "func literal does not escape"
+ func(x int) { // ERROR "can inline o.func2"
if x > 10 {
- foo = func() int { return 2 } // ERROR "can inline o.func2" "func literal escapes"
+ foo = func() int { return 2 } // ERROR "can inline o.func2"
}
- }(11)
+ }(11) // ERROR "func literal does not escape" "inlining call to o.func2"
return foo()
}
-func p() int {
+func p() int { // ERROR "can inline p"
return func() int { return 42 }() // ERROR "can inline p.func1" "inlining call to p.func1"
}
-func q(x int) int {
+func q(x int) int { // ERROR "can inline q"
foo := func() int { return x * 2 } // ERROR "can inline q.func1" "func literal does not escape"
return foo() // ERROR "inlining call to q.func1"
}
@@ -111,15 +111,15 @@ func r(z int) int {
foo := func(x int) int { // ERROR "can inline r.func1" "func literal does not escape"
return x + z
}
- bar := func(x int) int { // ERROR "func literal does not escape"
- return x + func(y int) int { // ERROR "can inline r.func2.1"
+ bar := func(x int) int { // ERROR "func literal does not escape" "can inline r.func2"
+ return x + func(y int) int { // ERROR "can inline r.func2.1" "can inline r.func3"
return 2*y + x*z
}(x) // ERROR "inlining call to r.func2.1"
}
- return foo(42) + bar(42) // ERROR "inlining call to r.func1"
+ return foo(42) + bar(42) // ERROR "inlining call to r.func1" "inlining call to r.func2" "inlining call to r.func3"
}
-func s0(x int) int {
+func s0(x int) int { // ERROR "can inline s0"
foo := func() { // ERROR "can inline s0.func1" "func literal does not escape"
x = x + 1
}
@@ -127,7 +127,7 @@ func s0(x int) int {
return x
}
-func s1(x int) int {
+func s1(x int) int { // ERROR "can inline s1"
foo := func() int { // ERROR "can inline s1.func1" "func literal does not escape"
return x
}