aboutsummaryrefslogtreecommitdiff
path: root/test/inline.go
diff options
context:
space:
mode:
Diffstat (limited to 'test/inline.go')
-rw-r--r--test/inline.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/inline.go b/test/inline.go
index 3edcf2edfd..9b75bc5065 100644
--- a/test/inline.go
+++ b/test/inline.go
@@ -49,6 +49,12 @@ func j(x int) int { // ERROR "can inline j"
}
}
+func _() int { // ERROR "can inline _"
+ tmp1 := h
+ tmp2 := tmp1
+ return tmp2(0) // ERROR "inlining call to h"
+}
+
var somethingWrong error
// local closures can be inlined
@@ -58,6 +64,9 @@ func l(x, y int) (int, int, error) {
}
if x == y {
e(somethingWrong) // ERROR "inlining call to l.func1"
+ } else {
+ f := e
+ f(nil) // ERROR "inlining call to l.func1"
}
return y, x, nil
}
@@ -197,3 +206,43 @@ func gg(x int) { // ERROR "can inline gg"
func hh(x int) { // ERROR "can inline hh"
ff(x - 1) // ERROR "inlining call to ff" // ERROR "inlining call to gg"
}
+
+// Issue #14768 - make sure we can inline for loops.
+func for1(fn func() bool) { // ERROR "can inline for1" "fn does not escape"
+ for {
+ if fn() {
+ break
+ } else {
+ continue
+ }
+ }
+}
+
+// BAD: for2 should be inlineable too.
+func for2(fn func() bool) { // ERROR "fn does not escape"
+Loop:
+ for {
+ if fn() {
+ break Loop
+ } else {
+ continue Loop
+ }
+ }
+}
+
+// Issue #18493 - make sure we can do inlining of functions with a method value
+type T1 struct{}
+
+func (a T1) meth(val int) int { // ERROR "can inline T1.meth" "inlining call to T1.meth"
+ return val + 5
+}
+
+func getMeth(t1 T1) func(int) int { // ERROR "can inline getMeth"
+ return t1.meth // ERROR "t1.meth escapes to heap"
+}
+
+func ii() { // ERROR "can inline ii"
+ var t1 T1
+ f := getMeth(t1) // ERROR "inlining call to getMeth" "t1.meth does not escape"
+ _ = f(3)
+}