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