Debian Codegraph @

gopls/internal/test/marker/testdata/implementation/embed-crosspkg.txt

raw
1 Test that an Implementation query correctly locates a method that is
2 promoted via embedding from a third package: the embedding package's
3 methodsets index does not store the method's position, so it must be
4 resolved at query time via the declaring package's index
5 (see methodsets.Index.LocationOf).
6
7 The interface I has two methods so that impl.T (which provides only M)
8 does not itself implement I; the only implementers are embed.S and
9 chain.S2, both of which acquire M by embedding. Thus the only path to
10 TM in the result of implementation("M", ...) is via cross-package
11 resolution. (A resolution failure would be caught by bug.PanicOnBugs
12 even though the result location—deduplicated—would otherwise look
13 correct.)
14
15 -- go.mod --
16 module example.com
17 go 1.18
18
19 -- iface/iface.go --
20 package iface
21
22 type I interface { //@loc(I, "I"),implementation("I", S, S2)
23 M() //@loc(IM, "M"),implementation("M", TM)
24 N() //@loc(IN, "N"),implementation("N", SN)
25 }
26
27 -- impl/impl.go --
28 package impl
29
30 type T struct{} //@loc(T, "T")
31
32 func (T) M() {} //@loc(TM, "M")
33
34 -- embed/embed.go --
35 package embed
36
37 import "example.com/impl"
38
39 // S implements iface.I: M is promoted from impl.T, N is declared here.
40 type S struct { //@loc(S, "S"),implementation("S", I)
41 impl.T
42 }
43
44 func (S) N() {} //@loc(SN, "N")
45
46 -- chain/chain.go --
47 package chain
48
49 import "example.com/embed"
50
51 // S2 tests two-level embedding: S2 → embed.S → impl.T.
52 // Both M (declaring package impl) and N (declaring package embed) are
53 // promoted, exercising resolution against two different indexes.
54 type S2 struct { //@loc(S2, "S2"),implementation("S2", I)
55 embed.S
56 }