1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // TODO: show that two-non-empty dotjoin can happen, by using an anon struct as a field type
6 // TODO: don't report removed/changed methods for both value and pointer method sets?
17 // There can be at most one message for each object or part thereof.
18 // Parts include interface methods and struct fields.
20 // The part thing is necessary. Method (Func) objects have sufficient info, but field
21 // Vars do not: they just have a field name and a type, without the enclosing struct.
22 type messageSet map[types.Object]map[string]string
24 // Add a message for obj and part, overwriting a previous message
25 // (shouldn't happen).
26 // obj is required but part can be empty.
27 func (m messageSet) add(obj types.Object, part, msg string) {
30 s = map[string]string{}
33 if f, ok := s[part]; ok && f != msg {
34 fmt.Printf("! second, different message for obj %s, part %q\n", obj, part)
35 fmt.Printf(" first: %s\n", f)
36 fmt.Printf(" second: %s\n", msg)
41 func (m messageSet) collect() []string {
43 for obj, parts := range m {
44 // Format each object name relative to its own package.
45 objstring := objectString(obj)
46 for part, msg := range parts {
49 if strings.HasPrefix(part, ",") {
52 p = dotjoin(objstring, part)
54 s = append(s, p+": "+msg)
61 func objectString(obj types.Object) string {
62 if f, ok := obj.(*types.Func); ok {
63 sig := f.Type().(*types.Signature)
64 if recv := sig.Recv(); recv != nil {
65 tn := types.TypeString(recv.Type(), types.RelativeTo(obj.Pkg()))
69 return fmt.Sprintf("%s.%s", tn, obj.Name())
75 func dotjoin(s1, s2 string) string {