| 1 | package main |
| 2 | |
| 3 | // Test of interface calls. None of the concrete types are ever |
| 4 | // instantiated or converted to interfaces. |
| 5 | |
| 6 | type I interface { |
| 7 | f() |
| 8 | } |
| 9 | |
| 10 | type J interface { |
| 11 | f() |
| 12 | g() |
| 13 | } |
| 14 | |
| 15 | type C int // implements I |
| 16 | |
| 17 | func (*C) f() |
| 18 | |
| 19 | type D int // implements I and J |
| 20 | |
| 21 | func (*D) f() |
| 22 | func (*D) g() |
| 23 | |
| 24 | func one(i I, j J) { |
| 25 | i.f() // calls *C and *D |
| 26 | } |
| 27 | |
| 28 | func two(i I, j J) { |
| 29 | j.f() // calls *D (but not *C, even though it defines method f) |
| 30 | } |
| 31 | |
| 32 | func three(i I, j J) { |
| 33 | j.g() // calls *D |
| 34 | } |
| 35 | |
| 36 | func four(i I, j J) { |
| 37 | Jf := J.f |
| 38 | if unknown { |
| 39 | Jf = nil // suppress SSA constant propagation |
| 40 | } |
| 41 | Jf(nil) // calls *D |
| 42 | } |
| 43 | |
| 44 | func five(i I, j J) { |
| 45 | jf := j.f |
| 46 | if unknown { |
| 47 | jf = nil // suppress SSA constant propagation |
| 48 | } |
| 49 | jf() // calls *D |
| 50 | } |
| 51 | |
| 52 | var unknown bool |
| 53 | |
| 54 | // WANT: |
| 55 | // Dynamic calls |
| 56 | // (J).f$bound --> (*D).f |
| 57 | // (J).f$thunk --> (*D).f |
| 58 | // five --> (J).f$bound |
| 59 | // four --> (J).f$thunk |
| 60 | // one --> (*C).f |
| 61 | // one --> (*D).f |
| 62 | // three --> (*D).g |
| 63 | // two --> (*D).f |