github.com/zebozhuang/go@v0.0.0-20200207033046-f8a98f6f5c5d/src/go/types/testdata/cycles2.src (about)

     1  // Copyright 2013 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  package p
     6  
     7  import "unsafe"
     8  
     9  // Test case for issue 5090
    10  
    11  type t interface {
    12  	f(u)
    13  }
    14  
    15  type u interface {
    16  	t
    17  }
    18  
    19  func _() {
    20  	var t t
    21  	var u u
    22  
    23  	t.f(t)
    24  	t.f(u)
    25  	
    26  	u.f(t)
    27  	u.f(u)
    28  }
    29  
    30  
    31  // Test case for issue 6589.
    32  
    33  type A interface {
    34  	a() interface {
    35  		AB
    36  	}
    37  }
    38  
    39  type B interface {
    40  	a() interface {
    41  		AB
    42  	}
    43  }
    44  
    45  type AB interface {
    46  	a() interface {
    47  		A
    48  		B /* ERROR a redeclared */
    49  	}
    50  	b() interface {
    51  		A
    52  		B /* ERROR a redeclared */
    53  	}
    54  }
    55  
    56  var x AB
    57  var y interface {
    58  	A
    59  	B /* ERROR a redeclared */
    60  }
    61  var _ = x /* ERROR cannot compare */ == y
    62  
    63  
    64  // Test case for issue 6638.
    65  
    66  type T interface {
    67  	m() [T /* ERROR no value */ (nil).m()[0]]int
    68  }
    69  
    70  // Variations of this test case.
    71  
    72  type T1 interface {
    73  	m() [x1 /* ERROR no value */ .m()[0]]int
    74  }
    75  
    76  var x1 T1
    77  
    78  type T2 interface {
    79  	m() [len(x2 /* ERROR no value */ .m())]int
    80  }
    81  
    82  var x2 T2
    83  
    84  type T3 interface {
    85  	m() [unsafe.Sizeof(x3.m)]int
    86  }
    87  
    88  var x3 T3
    89  
    90  // The test case below should also report an error for
    91  // the cast inside the T4 interface (like it does for the
    92  // variable initialization). The reason why it does not is
    93  // that inside T4, the method x4.m depends on T4 which is not
    94  // fully set up yet. The x4.m method happens to have an empty
    95  // signature which is why the cast is permitted.
    96  // TODO(gri) Consider marking methods as incomplete and provide
    97  // a better error message in that case.
    98  
    99  type T4 interface {
   100  	m() [unsafe.Sizeof(cast4(x4.m))]int
   101  }
   102  
   103  var x4 T4
   104  var _ = cast4(x4 /* ERROR cannot convert */.m)
   105  
   106  type cast4 func()
   107  
   108  // This test is symmetric to the T4 case: Here the cast is
   109  // "correct", but it doesn't work inside the T5 interface.
   110  
   111  type T5 interface {
   112  	m() [unsafe.Sizeof(cast5(x5 /* ERROR cannot convert */ .m))]int
   113  }
   114  
   115  var x5 T5
   116  var _ = cast5(x5.m)
   117  
   118  type cast5 func() [0]int