| 1 |
// Copyright 2020 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package a |
| 6 |
|
| 7 |
type I interface{ M() } |
| 8 |
type T int |
| 9 |
|
| 10 |
func (T) M() {} // ERROR "can inline T.M" |
| 11 |
|
| 12 |
func E() I { // ERROR "can inline E" |
| 13 |
return T(0) // ERROR "T\(0\) escapes to heap" |
| 14 |
} |
| 15 |
|
| 16 |
func F(i I) I { // ERROR "can inline F" "leaking param: i to result ~r0 level=0" |
| 17 |
i = nil |
| 18 |
return i |
| 19 |
} |
| 20 |
|
| 21 |
func g() { |
| 22 |
h := E() // ERROR "inlining call to E" "T\(0\) does not escape" |
| 23 |
h.M() // ERROR "devirtualizing h.M to T" "inlining call to T.M" |
| 24 |
|
| 25 |
i := F(T(0)) // ERROR "inlining call to F" "T\(0\) does not escape" |
| 26 |
|
| 27 |
// It is fine that we devirtualize here, as we add an additional nilcheck. |
| 28 |
i.M() // ERROR "devirtualizing i.M to T" "inlining call to T.M" |
| 29 |
} |