On Wednesday, October 25, 2017 at 4:51:08 AM UTC-4, Harald Fuchs wrote:
>
> I got bitten by what I'd say is a misfeature in Go: 
>
>   type T1 struct { 
>     T2 
>     T3 
>   } 
>
>   type T2 struct { 
>     T4 
>   } 
>
>   type T3 struct { 
>     foo int 
>   } 
>
>   type T4 struct { 
>     foo int 
>   } 
>
>   func main() { 
>     t1 := T1{ 
>       T2{ 
>         T4{ 
>           1, 
>         }, 
>       }, 
>       T3{ 
>         2, 
>       }, 
>     } 
>     fmt.Printf("foo=%d\n", t1.foo) 
>   } 
>
> This prints "foo=2" which surprised me because I was unaware that T1 
> had got another foo via T3 (with less composition depth). 
>
> If I put T4 directly into T1, Go would detect the ambiguity of t1.foo 
> (because the composition depth is the same). 
>
>
The full selector path of T4.foo for T1 is T1.T2.T4.foo,
The full selector path of T3.foo for T1 is T1.T3.foo.
The shortest one will suppress the longer one.
If there are more than two shortest ones, then they collide, none of them 
will be promoted.
 

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