The two type a.Arg and b.Arg are different type because the live in
different packages. Same for a.Worker and b.Worker. Different
packages --> different types. Laxing this rule would open a can of
worms: Suddenly your axis.Point and rating.Point become
assignable, just because the "are the same". Laxing this rule
for interfaces is as problematic and complicates the language.
V.
On Friday, 10 March 2017 09:22:17 UTC+1, Henry wrote:
>
> Hi,
>
> I notice Go's compiler examines the interface signature somewhat
> superficially. It is best to explain the situation using code:
>
> Given in Package a,
>
> package a
>
> type Arg interface{
> DoSomething()
> }
>
> type Worker interface{
> Work(arg Arg)
> }
>
> func NewWorker() Worker{
> //...
> }
>
> Then Package a is consumed in Package b,
>
> package b
>
> type Arg interface{
> DoSomething()
> }
>
> type Worker interface{
> Work(arg Arg)
> }
>
> func SomewhereInB(){
> var worker Worker
> worker = a.NewWorker() //compile failure: worker does not implement
> Work(b.Arg)
> //...
> }
>
>
> I believe the compiler should be able to deduce that a.Arg and b.Arg are
> identical and therefore Work(a.Arg) and Work(b.Arg) should also be
> identical. Thus, a.Worker and b.Worker are identical. The compiler fails to
> recognize this. Is this a bug?
>
> Thanks.
>
> Henry
>
>
>
>
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.