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

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