I'm posting here rather than filing a proposal on github, because I don't know the history of this idea.
Would it make sense to have the compiler loosen its type checking when using the same interface but with different names?
There are two places this would help:
- using a vendored version of an interface. Example discussions abound.
The big problem occurs when comparing types that contain the interface type. For example, function parameter types:
package main
import (
"fmt"
"time"
)
type Stringer interface {
String() string
}
func func1(s Stringer) {}
func func2(s fmt.Stringer) {}
func func3(f func(s Stringer)) {}
func func4(f func(s fmt.Stringer)) {}
func main() {
e := time.Second // valid Stringer
func1(e) // ok
func2(e) // ok
func3(func1) // ok
func4(func1) // cannot use func1 (type func(Stringer)) as type func(fmt.Stringer) in argument to func4
}
Zellyn