MCPcopy Create free account
hub / github.com/despiteallobjections/amigo / TestNewMethodSet

Function TestNewMethodSet

types/methodset_test.go:13–109  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestNewMethodSet(t *testing.T) {
14 type method struct {
15 name string
16 index []int
17 indirect bool
18 }
19
20 // Tests are expressed src -> methods, for simplifying the composite literal.
21 // Should be kept in sync with TestLookupFieldOrMethod.
22 tests := map[string][]method{
23 // Named types
24 "var a T; type T struct{}; func (T) f() {}": {{"f", []int{0}, false}},
25 "var a *T; type T struct{}; func (T) f() {}": {{"f", []int{0}, true}},
26 "var a T; type T struct{}; func (*T) f() {}": {},
27 "var a *T; type T struct{}; func (*T) f() {}": {{"f", []int{0}, true}},
28
29 // Interfaces
30 "var a T; type T interface{ f() }": {{"f", []int{0}, true}},
31 "var a T1; type ( T1 T2; T2 interface{ f() } )": {{"f", []int{0}, true}},
32 "var a T1; type ( T1 interface{ T2 }; T2 interface{ f() } )": {{"f", []int{0}, true}},
33
34 // Embedding
35 "var a struct{ E }; type E interface{ f() }": {{"f", []int{0, 0}, true}},
36 "var a *struct{ E }; type E interface{ f() }": {{"f", []int{0, 0}, true}},
37 "var a struct{ E }; type E struct{}; func (E) f() {}": {{"f", []int{0, 0}, false}},
38 "var a struct{ *E }; type E struct{}; func (E) f() {}": {{"f", []int{0, 0}, true}},
39 "var a struct{ E }; type E struct{}; func (*E) f() {}": {},
40 "var a struct{ *E }; type E struct{}; func (*E) f() {}": {{"f", []int{0, 0}, true}},
41
42 // collisions
43 "var a struct{ E1; *E2 }; type ( E1 interface{ f() }; E2 struct{ f int })": {},
44 "var a struct{ E1; *E2 }; type ( E1 struct{ f int }; E2 struct{} ); func (E2) f() {}": {},
45 }
46
47 genericTests := map[string][]method{
48 // By convention, look up a in the scope of "g"
49 "type C interface{ f() }; func g[T C](a T){}": {{"f", []int{0}, true}},
50 "type C interface{ f() }; func g[T C]() { var a T; _ = a }": {{"f", []int{0}, true}},
51
52 // Issue #43621: We don't allow this anymore. Keep this code in case we
53 // decide to revisit this decision.
54 // "type C interface{ f() }; func g[T C]() { var a struct{T}; _ = a }": {{"f", []int{0, 0}, true}},
55
56 // Issue #45639: We also don't allow this anymore.
57 // "type C interface{ f() }; func g[T C]() { type Y T; var a Y; _ = a }": {},
58 }
59
60 check := func(src string, methods []method, generic bool) {
61 pkgName := "p"
62 if generic {
63 // The generic_ prefix causes pkgFor to allow generic code.
64 pkgName = "generic_p"
65 }
66 pkg, err := pkgFor("test", "package "+pkgName+";"+src, nil)
67 if err != nil {
68 t.Errorf("%s: incorrect test case: %s", src, err)
69 return
70 }

Callers

nothing calls this directly

Calls 12

LenMethod · 0.95
AtMethod · 0.95
pkgForFunction · 0.85
NewMethodSetFunction · 0.85
sameSliceFunction · 0.85
IndirectMethod · 0.80
TypeMethod · 0.65
NameMethod · 0.65
ScopeMethod · 0.45
LookupMethod · 0.45
ObjMethod · 0.45
IndexMethod · 0.45

Tested by

no test coverage detected