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