aboutsummaryrefslogtreecommitdiff
path: root/src/go/types/testdata/check/cycles4.src
blob: 924aabf475f9640cdfa6da8834fa9a8db6aa0a2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package p

import "unsafe"

// Check that all methods of T are collected before
// determining the result type of m (which embeds
// all methods of T).

type T interface {
	m() interface {T}
	E
}

var _ int = T.m(nil).m().e()

type E interface {
	e() int
}

// Check that unresolved forward chains are followed
// (see also comment in resolver.go, checker.typeDecl).

var _ int = C.m(nil).m().e()

type A B

type B interface {
	m() interface{C}
	E
}

type C A

// Check that interface type comparison for identity
// does not recur endlessly.

type T1 interface {
	m() interface{T1}
}

type T2 interface {
	m() interface{T2}
}

func _(x T1, y T2) {
	// Checking for assignability of interfaces must check
	// if all methods of x are present in y, and that they
	// have identical signatures. The signatures recur via
	// the result type, which is an interface that embeds
	// a single method m that refers to the very interface
	// that contains it. This requires cycle detection in
	// identity checks for interface types.
	x = y
}

type T3 interface {
	m() interface{T4}
}

type T4 interface {
	m() interface{T3}
}

func _(x T1, y T3) {
	x = y
}

// Check that interfaces are type-checked in order of
// (embedded interface) dependencies (was issue 7158).

var x1 T5 = T7(nil)

type T5 interface {
	T6
}

type T6 interface {
	m() T7
}
type T7 interface {
	T5
}

// Actual test case from issue 7158.

func wrapNode() Node {
	return wrapElement()
}

func wrapElement() Element {
	return nil
}

type EventTarget interface {
	AddEventListener(Event)
}

type Node interface {
	EventTarget
}

type Element interface {
	Node
}

type Event interface {
	Target() Element
}

// Check that accessing an interface method too early doesn't lead
// to follow-on errors due to an incorrectly computed type set.

type T8 interface {
	m() [unsafe.Sizeof(T8.m /* ERROR undefined */ )]int
}

var _ = T8.m // no error expected here