| 1 |
Test of references applied to concrete and interface types that are |
| 2 |
related by assignability. The result includes references to both. |
| 3 |
|
| 4 |
-- go.mod -- |
| 5 |
module example.com |
| 6 |
go 1.12 |
| 7 |
|
| 8 |
-- a/a.go -- |
| 9 |
package a |
| 10 |
|
| 11 |
type first interface { |
| 12 |
common() //@loc(firCommon, "common"), refs("common", firCommon, xCommon, zCommon) |
| 13 |
firstMethod() //@loc(firMethod, "firstMethod"), refs("firstMethod", firMethod, xfMethod, zfMethod) |
| 14 |
} |
| 15 |
|
| 16 |
type second interface { |
| 17 |
common() //@loc(secCommon, "common"), refs("common", secCommon, yCommon, zCommon) |
| 18 |
secondMethod() //@loc(secMethod, "secondMethod"), refs("secondMethod", secMethod, ysMethod, zsMethod) |
| 19 |
} |
| 20 |
|
| 21 |
type s struct {} |
| 22 |
|
| 23 |
func (*s) common() {} //@loc(sCommon, "common"), refs("common", sCommon, xCommon, yCommon, zCommon) |
| 24 |
|
| 25 |
func (*s) firstMethod() {} //@loc(sfMethod, "firstMethod"), refs("firstMethod", sfMethod, xfMethod, zfMethod) |
| 26 |
|
| 27 |
func (*s) secondMethod() {} //@loc(ssMethod, "secondMethod"), refs("secondMethod", ssMethod, ysMethod, zsMethod) |
| 28 |
|
| 29 |
func main() { |
| 30 |
var x first = &s{} |
| 31 |
var y second = &s{} |
| 32 |
|
| 33 |
x.common() //@loc(xCommon, "common"), refs("common", firCommon, xCommon, zCommon) |
| 34 |
x.firstMethod() //@loc(xfMethod, "firstMethod"), refs("firstMethod", firMethod, xfMethod, zfMethod) |
| 35 |
y.common() //@loc(yCommon, "common"), refs("common", secCommon, yCommon, zCommon) |
| 36 |
y.secondMethod() //@loc(ysMethod, "secondMethod"), refs("secondMethod", secMethod, ysMethod, zsMethod) |
| 37 |
|
| 38 |
var z *s = &s{} |
| 39 |
z.firstMethod() //@loc(zfMethod, "firstMethod"), refs("firstMethod", sfMethod, xfMethod, zfMethod) |
| 40 |
z.secondMethod() //@loc(zsMethod, "secondMethod"), refs("secondMethod", ssMethod, ysMethod, zsMethod) |
| 41 |
z.common() //@loc(zCommon, "common"), refs("common", sCommon, xCommon, yCommon, zCommon) |
| 42 |
} |