| 1 | // Copyright 2021 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 | // go:build ignore |
| 6 | |
| 7 | package testdata |
| 8 | |
| 9 | type Y interface { |
| 10 | Foo() |
| 11 | Bar(float64) |
| 12 | } |
| 13 | |
| 14 | type Z Y |
| 15 | |
| 16 | type W interface { |
| 17 | Y |
| 18 | } |
| 19 | |
| 20 | type A struct{} |
| 21 | |
| 22 | func (a A) Foo() { print("A:Foo") } |
| 23 | func (a A) Bar(f float64) { print(uint(f)) } |
| 24 | |
| 25 | type B struct{} |
| 26 | |
| 27 | func (b B) Foo() { print("B:Foo") } |
| 28 | func (b B) Bar(f float64) { print(uint(f) + 1) } |
| 29 | |
| 30 | type X interface { |
| 31 | Foo() |
| 32 | } |
| 33 | |
| 34 | func Baz(y Y) { |
| 35 | z := Z(y) |
| 36 | z.Foo() |
| 37 | |
| 38 | x := X(y) |
| 39 | x.Foo() |
| 40 | |
| 41 | y = A{} |
| 42 | var y_p *Y = &y |
| 43 | |
| 44 | w_p := (*W)(y_p) |
| 45 | *w_p = B{} |
| 46 | |
| 47 | (*y_p).Foo() // prints B:Foo |
| 48 | (*w_p).Foo() // prints B:Foo |
| 49 | } |
| 50 | |
| 51 | // Relevant SSA: |
| 52 | // func Baz(y Y): |
| 53 | // t0 = new Y (y) |
| 54 | // *t0 = y |
| 55 | // t1 = *t0 |
| 56 | // t2 = changetype Z <- Y (t1) |
| 57 | // t3 = invoke t2.Foo() |
| 58 | // |
| 59 | // t4 = *t0 |
| 60 | // t5 = change interface X <- Y (t4) |
| 61 | // t6 = invoke t5.Foo() |
| 62 | // |
| 63 | // t7 = local A (complit) |
| 64 | // t8 = *t7 |
| 65 | // t9 = make Y <- A (t8) |
| 66 | // *t0 = t9 |
| 67 | // t10 = changetype *W <- *Y (t0) |
| 68 | // t11 = local B (complit) |
| 69 | // t12 = *t11 |
| 70 | // t13 = make W <- B (t12) |
| 71 | // *t10 = t13 |
| 72 | // t14 = *t0 |
| 73 | // t15 = invoke t14.Foo() |
| 74 | // t16 = *t10 |
| 75 | // t17 = invoke t16.Foo() |
| 76 | // return |
| 77 | |
| 78 | // WANT: |
| 79 | // Local(t1) -> Local(t2) |
| 80 | // Local(t4) -> Local(t5) |
| 81 | // Local(t0) -> Local(t1), Local(t10), Local(t14), Local(t4) |
| 82 | // Local(y) -> Local(t0) |
| 83 | // Local(t8) -> Local(t9) |
| 84 | // Local(t9) -> Local(t0) |
| 85 | // Local(t13) -> Local(t10) |
| 86 |