Situation
Barhas a methodGet()with a signature*FooFooimplements 2 interfacesI_Venus1andI_Mars1.I_Venus2has a methodGet()with a signatureI_Venus1I_Mars2has a methodGet()with a signatureI_Mars1.
type Foo struct {
}
type Bar struct {
}
func (*Bar) Get() *Foo {
return nil
}
type I_Venus1 interface {
}
type I_Venus2 interface {
Get() I_Venus1
}
type I_Mars1 interface {
}
type I_Mars2 interface {
Get() I_Mars1
}
var _ I_Venus1 = &(Foo{}) // Foo meets I_Venus1 interface
var _ I_Mars1 = &(Foo{}) // Foo meets I_Mars1 interface
Problem
var _ I_Venus2 = &(Bar{}) // *Bar does not implement I_Venus2 (wrong type for method Get)
var _ I_Mars2 = &(Bar{}) // *Bar does not implement I_Mars2 (wrong type for method Get)
I do not understand what prevents the go compiler from deciding that Bar implements both I_Venus2 and I_Mars1 interfaces.
Note : this question is a variation on
Go Interface Method Returning Interface Doesn't Match Method Returning Concrete Type
Bar.Get()returns*FoowhereasI_Venus1.Get()returnsI_Venus1andI_Mars2.Get()returnsI_Mars1.*Foo≠I_Venus1≠I_Mars1