Home | History | Annotate | Download | only in testdata
      1 // Copyright 2012 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 // The package e is a go/doc test for embedded methods.
      6 package e
      7 
      8 // ----------------------------------------------------------------------------
      9 // Conflicting methods M must not show up.
     10 
     11 type t1 struct{}
     12 
     13 // t1.M should not appear as method in a Tx type.
     14 func (t1) M() {}
     15 
     16 type t2 struct{}
     17 
     18 // t2.M should not appear as method in a Tx type.
     19 func (t2) M() {}
     20 
     21 // T1 has no embedded (level 1) M method due to conflict.
     22 type T1 struct {
     23 	t1
     24 	t2
     25 }
     26 
     27 // ----------------------------------------------------------------------------
     28 // Higher-level method M wins over lower-level method M.
     29 
     30 // T2 has only M as top-level method.
     31 type T2 struct {
     32 	t1
     33 }
     34 
     35 // T2.M should appear as method of T2.
     36 func (T2) M() {}
     37 
     38 // ----------------------------------------------------------------------------
     39 // Higher-level method M wins over lower-level conflicting methods M.
     40 
     41 type t1e struct {
     42 	t1
     43 }
     44 
     45 type t2e struct {
     46 	t2
     47 }
     48 
     49 // T3 has only M as top-level method.
     50 type T3 struct {
     51 	t1e
     52 	t2e
     53 }
     54 
     55 // T3.M should appear as method of T3.
     56 func (T3) M() {}
     57 
     58 // ----------------------------------------------------------------------------
     59 // Don't show conflicting methods M embedded via an exported and non-exported
     60 // type.
     61 
     62 // T1 has no embedded (level 1) M method due to conflict.
     63 type T4 struct {
     64 	t2
     65 	T2
     66 }
     67 
     68 // ----------------------------------------------------------------------------
     69 // Don't show embedded methods of exported anonymous fields unless AllMethods
     70 // is set.
     71 
     72 type T4 struct{}
     73 
     74 // T4.M should appear as method of T5 only if AllMethods is set.
     75 func (*T4) M() {}
     76 
     77 type T5 struct {
     78 	T4
     79 }
     80 
     81 // ----------------------------------------------------------------------------
     82 // Recursive type declarations must not lead to endless recursion.
     83 
     84 type U1 struct {
     85 	*U1
     86 }
     87 
     88 // U1.M should appear as method of U1.
     89 func (*U1) M() {}
     90 
     91 type U2 struct {
     92 	*U3
     93 }
     94 
     95 // U2.M should appear as method of U2 and as method of U3 only if AllMethods is set.
     96 func (*U2) M() {}
     97 
     98 type U3 struct {
     99 	*U2
    100 }
    101 
    102 // U3.N should appear as method of U3 and as method of U2 only if AllMethods is set.
    103 func (*U3) N() {}
    104 
    105 type U4 struct {
    106 	*u5
    107 }
    108 
    109 // U4.M should appear as method of U4.
    110 func (*U4) M() {}
    111 
    112 type u5 struct {
    113 	*U4
    114 }
    115 
    116 // ----------------------------------------------------------------------------
    117 // A higher-level embedded type (and its methods) wins over the same type (and
    118 // its methods) embedded at a lower level.
    119 
    120 type V1 struct {
    121 	*V2
    122 	*V5
    123 }
    124 
    125 type V2 struct {
    126 	*V3
    127 }
    128 
    129 type V3 struct {
    130 	*V4
    131 }
    132 
    133 type V4 struct {
    134 	*V5
    135 }
    136 
    137 type V5 struct {
    138 	*V6
    139 }
    140 
    141 type V6 struct{}
    142 
    143 // V4.M should appear as method of V2 and V3 if AllMethods is set.
    144 func (*V4) M() {}
    145 
    146 // V6.M should appear as method of V1 and V5 if AllMethods is set.
    147 func (*V6) M() {}
    148