github.com/zebozhuang/go@v0.0.0-20200207033046-f8a98f6f5c5d/src/go/types/testdata/cycles1.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  type (
     8  	A interface {
     9  		a() interface {
    10  			ABC1
    11  		}
    12  	}
    13  	B interface {
    14  		b() interface {
    15  			ABC2
    16  		}
    17  	}
    18  	C interface {
    19  		c() interface {
    20  			ABC3
    21  		}
    22  	}
    23  
    24  	AB interface {
    25  		A
    26  		B
    27  	}
    28  	BC interface {
    29  		B
    30  		C
    31  	}
    32  
    33  	ABC1 interface {
    34  		A
    35  		B
    36  		C
    37  	}
    38  	ABC2 interface {
    39  		AB
    40  		C
    41  	}
    42  	ABC3 interface {
    43  		A
    44  		BC
    45  	}
    46  )
    47  
    48  var (
    49  	x1 ABC1
    50  	x2 ABC2
    51  	x3 ABC3
    52  )
    53  
    54  func _() {
    55  	// all types have the same method set
    56  	x1 = x2
    57  	x2 = x1
    58  
    59  	x1 = x3
    60  	x3 = x1
    61  
    62  	x2 = x3
    63  	x3 = x2
    64  
    65  	// all methods return the same type again
    66  	x1 = x1.a()
    67  	x1 = x1.b()
    68  	x1 = x1.c()
    69  
    70  	x2 = x2.a()
    71  	x2 = x2.b()
    72  	x2 = x2.c()
    73  
    74  	x3 = x3.a()
    75  	x3 = x3.b()
    76  	x3 = x3.c()
    77  }