Black Lives Matter. Support the Equal Justice Initiative.

Text file src/go/types/testdata/check/cycles4.src

Documentation: go/types/testdata/check

     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  // Check that all methods of T are collected before
     8  // determining the result type of m (which embeds
     9  // all methods of T).
    10  
    11  type T interface {
    12  	m() interface {T}
    13  	E
    14  }
    15  
    16  var _ = T.m(nil).m().e()
    17  
    18  type E interface {
    19  	e() int
    20  }
    21  
    22  // Check that unresolved forward chains are followed
    23  // (see also comment in resolver.go, checker.typeDecl).
    24  
    25  var _ = C.m(nil).m().e()
    26  
    27  type A B
    28  
    29  type B interface {
    30  	m() interface{C}
    31  	E
    32  }
    33  
    34  type C A
    35  
    36  // Check that interface type comparison for identity
    37  // does not recur endlessly.
    38  
    39  type T1 interface {
    40  	m() interface{T1}
    41  }
    42  
    43  type T2 interface {
    44  	m() interface{T2}
    45  }
    46  
    47  func _(x T1, y T2) {
    48  	// Checking for assignability of interfaces must check
    49  	// if all methods of x are present in y, and that they
    50  	// have identical signatures. The signatures recur via
    51  	// the result type, which is an interface that embeds
    52  	// a single method m that refers to the very interface
    53  	// that contains it. This requires cycle detection in
    54  	// identity checks for interface types.
    55  	x = y
    56  }
    57  
    58  type T3 interface {
    59  	m() interface{T4}
    60  }
    61  
    62  type T4 interface {
    63  	m() interface{T3}
    64  }
    65  
    66  func _(x T1, y T3) {
    67  	x = y
    68  }
    69  
    70  // Check that interfaces are type-checked in order of
    71  // (embedded interface) dependencies (was issue 7158).
    72  
    73  var x1 T5 = T7(nil)
    74  
    75  type T5 interface {
    76  	T6
    77  }
    78  
    79  type T6 interface {
    80  	m() T7
    81  }
    82  type T7 interface {
    83  	T5
    84  }
    85  
    86  // Actual test case from issue 7158.
    87  
    88  func wrapNode() Node {
    89  	return wrapElement()
    90  }
    91  
    92  func wrapElement() Element {
    93  	return nil
    94  }
    95  
    96  type EventTarget interface {
    97  	AddEventListener(Event)
    98  }
    99  
   100  type Node interface {
   101  	EventTarget
   102  }
   103  
   104  type Element interface {
   105  	Node
   106  }
   107  
   108  type Event interface {
   109  	Target() Element
   110  }
   111  

View as plain text