type Celsius float64
func (c Celsius) String() string { return fmt.Sprintf("%g°C", c) }
func (c *Celsius) SetF(f float64) { *c = Celsius(f - 32 / 9 * 5) }
+
+type S struct { I; m int }
+type I interface { m() byte }
`
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "celsius.go", input, 0)
fmt.Println()
}
+ // Print the method set of S.
+ styp := pkg.Scope().Lookup("S").Type()
+ fmt.Printf("Method set of %s:\n", styp)
+ fmt.Println(types.NewMethodSet(styp))
+
// Output:
// Method set of temperature.Celsius:
// method (temperature.Celsius) String() string
// Method set of *temperature.Celsius:
// method (*temperature.Celsius) SetF(f float64)
// method (*temperature.Celsius) String() string
+ //
+ // Method set of temperature.S:
+ // MethodSet {}
}
// ExampleInfo prints various facts recorded by the type checker in a
}
}
- // Multiple fields with matching names collide at this depth and shadow all
- // entries further down; add them as collisions to base if no entries with
- // matching names exist already.
- for k, f := range fset {
- if f == nil {
- if _, found := base[k]; !found {
- if base == nil {
- base = make(methodSet)
- }
- base[k] = nil // collision
+ // Add all fields at this depth as collisions (since they will hide any
+ // method further down) to base if no entries with matching names exist
+ // already.
+ for k := range fset {
+ if _, found := base[k]; !found {
+ if base == nil {
+ base = make(methodSet)
}
+ base[k] = nil // collision
}
}
// A methodSet is a set of methods and name collisions.
// A collision indicates that multiple methods with the
-// same unique id appeared.
+// same unique id, or a field with that id appeared.
type methodSet map[string]*Selection // a nil entry indicates a name collision
// Add adds all functions in list to the method set s.