Map handling builtins getIndexMap and rangeMap had some leftover code of previous way of emulating interfaces, which was modified following changes in #1017. Specific code for interfaceT is removed, as not necessary anymore. Map builtins are now simplified and more robust. Fixes #1189.
32 lines
373 B
Go
32 lines
373 B
Go
package main
|
|
|
|
type I interface {
|
|
Foo() int
|
|
}
|
|
|
|
type S1 struct {
|
|
i int
|
|
}
|
|
|
|
func (s S1) Foo() int { return s.i }
|
|
|
|
type S2 struct{}
|
|
|
|
func (s *S2) Foo() int { return 42 }
|
|
|
|
func main() {
|
|
Is := map[string]I{
|
|
"foo": S1{21},
|
|
"bar": &S2{},
|
|
}
|
|
n := 0
|
|
for _, s := range Is {
|
|
n += s.Foo()
|
|
}
|
|
bar := "bar"
|
|
println(n, Is["foo"].Foo(), Is[bar].Foo())
|
|
}
|
|
|
|
// Output:
|
|
// 63 21 42
|