diff options
author | Cherry Zhang <cherryyz@google.com> | 2020-10-28 09:12:20 -0400 |
---|---|---|
committer | Cherry Zhang <cherryyz@google.com> | 2020-10-28 09:12:20 -0400 |
commit | a16e30d162c1c7408db7821e7b9513cefa09c6ca (patch) | |
tree | af752ba9ba44c547df39bb0af9bff79f610ba9d5 /test/inline.go | |
parent | 91e4d2d57bc341dd82c98247117114c851380aef (diff) | |
parent | cf6cfba4d5358404dd890f6025e573a4b2156543 (diff) | |
download | go-git-dev.link.tar.gz |
[dev.link] all: merge branch 'master' into dev.linkdev.link
Clean merge.
Change-Id: Ia7b2808bc649790198d34c226a61d9e569084dc5
Diffstat (limited to 'test/inline.go')
-rw-r--r-- | test/inline.go | 49 |
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) +} |