Hi !

Today i found a weird thing in the Golang type checker.

I have a package with the following architecture:


type A interface {
>     D()
> }
>
> type B struct {
>     *C
> }
>
> func (t B) NotD() {}
>
> type C struct{
>     A
> }
>


And when i did:
 

> var _ A = (*B)(nil)
>

I excpected the Compiler to return me an error like:

 cannot use (*B)(nil) (type *B) as type A in assignment:
>       *B does not implement A (missing D method)
>
>
But the compiler didn't complain at all and let me compile the code.
I can even do some weird things like that:

var a A = (*B)(nil)
> a.D()
>

The compiler will produce a binary without complaining but it panic 
(obviously)

(You can find this example here: https://play.golang.org/p/c8-rNHDqup)

Curiously enough, naming C, will fix the issue (see 
https://play.golang.org/p/VqxCRxu2hi)

Is that a bug in the golang type checker or am i missing something.

Thanks,

Jonathan Hurter

-- 
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