This is a result of the assignability requirement of the spec:
https://golang.org/ref/spec#Comparison_operators
In this particular case, IAB is assignable to IA, so it's a valid
comparison:
https://golang.org/ref/spec#Assignability
("T is an interface type and x implements T" -- a value of type IA
implements IAB and IAC)
But IAC is not assignable to IAB or vice versa. Thus the comparison is not
valid.

So, no, I don't think it's an entirely intentional effect, but a
side-effect of the assignability-requirement. Using assignability as a
requirement for comparisons instead of type-equality makes some things more
convenient. And that IAC isn't assignable to IAB or vice versa makes total
sense.

On Sun, Jul 31, 2016 at 6:23 PM, T L <tapir....@gmail.com> wrote:

>
>
> On Sunday, July 31, 2016 at 11:46:28 PM UTC+8, bradfitz wrote:
>>
>> Interface values are comparable. If they have different concrete types,
>> they compare to false.
>>
>> See https://golang.org/ref/spec#Comparison_operators
>>
>
> I mean this:
>
>> package main
>>
>> import "fmt"
>>
>> type IA interface {
>>     A()
>> }
>>
>> type IAB interface {
>>     A()
>>     B()
>> }
>>
>> type IAC interface {
>>     A()
>>     C()
>> }
>>
>> type T struct{}
>> func (t T) A(){}
>> func (t T) B(){}
>> func (t T) C(){}
>>
>> func main() {
>>     var t T
>>     var a IA = t
>>     var ab IAB = t
>>     var ac IAC = t
>>
>>     fmt.Println(a == ab) // true
>>     fmt.Println(ac == ab) // error: mismatched types IAC and IAB
>> }
>>
>
>
>>
>>
>> On Sat, Jul 30, 2016 at 10:33 PM, T L <tapi...@gmail.com> wrote:
>>
>>> Is it essential?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to golang-nuts...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to