Hacker News new | ask | show | jobs
by kune 980 days ago
The statement "An interface type A is assignable to interface type B if A’s methods are a subset of B’s." is wrong. It is not in the current language specification of Go. The author misunderstood the term type set from the Go language specification. The type set of an interface is the set of types implementing the interface and not the set of methods of an interface. If you use the right meaning of type set, the subset makes sense again.
1 comments

It's not wrong, https://go.dev/ref/spec#Assignability:

    > A value x of type V is assignable to a variable of type T ("x is assignable to T") if
    > ...
    > T is an interface type, but not a type parameter, and x implements[1] T
[1]: https://go.dev/ref/spec#Implementing_an_interface:

    > A type T implements an interface I if:
    > ...
    > T is an interface and the type set of T is a subset of the type set of I
It’s backwards. For A to be assignable to B, A must implement B, so A’s methods must be a superset of B’s.
Ah, now I get it - sorry for adding to the confusion!