You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sema: Check generic requirements of parent context when realizing non-generic types
When realizing a type like Foo<A>.Bar, we have to account for the
possibility that Bar is defined in a constrained extension of Foo,
and has generic requirements beyond those that Foo itself places
on 'A'.
Previously we only handled this for types referenced from the
constraint system as part of openUnboundGenericType(), so we were
allowing invalid types through in type context.
Add the right checking to applyGenericArguments() to close the
hole. Note that the old code path still exists in the constraint
solver; it is used for member accesses on metatype bases only.
Fixes <https://bugs.swift.org/browse/SR-10466>.
Copy file name to clipboardExpand all lines: test/Constraints/conditionally_defined_types.swift
+46-55Lines changed: 46 additions & 55 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ struct Z2: AssociatedType {
15
15
}
16
16
17
17
structSameType<T>{}
18
-
extensionSameTypewhere T ==X{ // expected-note 5 {{where 'T' = 'Y'}}
18
+
extensionSameTypewhere T ==X{ // expected-note 13{{requirement specified as 'T' == 'X' [with T = Y]}}
19
19
typealiasTypeAlias1=T
20
20
typealiasTypeAlias2=Y
21
21
typealiasTypeAlias3<U>=(T,U) // expected-note {{requirement specified as 'T' == 'X' [with T = Y]}}
@@ -36,25 +36,24 @@ let _ = SameType<X>.Decl3.self
36
36
let _ =SameType<X>.Decl4<X>.self
37
37
let _ =SameType<X>.Decl5<X>.self
38
38
39
-
let _ =SameType<Y>.TypeAlias1.self // expected-error {{referencing type alias 'TypeAlias1' on 'SameType' requires the types 'Y' and 'X' be equivalent}}
40
-
let _ =SameType<Y>.TypeAlias2.self // expected-error {{referencing type alias 'TypeAlias2' on 'SameType' requires the types 'Y' and 'X' be equivalent}}
39
+
let _ =SameType<Y>.TypeAlias1.self // expected-error {{'SameType<Y>.TypeAlias1' (aka 'X') requires the types 'Y' and 'X' be equivalent}}
40
+
let _ =SameType<Y>.TypeAlias2.self // expected-error {{'SameType<Y>.TypeAlias2' (aka 'Y') requires the types 'Y' and 'X' be equivalent}}
41
41
let _ =SameType<Y>.TypeAlias3<X>.self // expected-error {{'SameType<Y>.TypeAlias3' requires the types 'Y' and 'X' be equivalent}}
42
-
let _ =SameType<Y>.Decl1.self // expected-error {{referencing struct 'Decl1' on 'SameType' requires the types 'Y' and 'X' be equivalent}}
43
-
let _ =SameType<Y>.Decl2.self // expected-error {{referencing enum 'Decl2' on 'SameType' requires the types 'Y' and 'X' be equivalent}}
44
-
let _ =SameType<Y>.Decl3.self // expected-error {{referencing class 'Decl3' on 'SameType' requires the types 'Y' and 'X' be equivalent}}
42
+
let _ =SameType<Y>.Decl1.self // expected-error {{'SameType<Y>.Decl1' requires the types 'Y' and 'X' be equivalent}}
43
+
let _ =SameType<Y>.Decl2.self // expected-error {{'SameType<Y>.Decl2' requires the types 'Y' and 'X' be equivalent}}
44
+
let _ =SameType<Y>.Decl3.self // expected-error {{'SameType<Y>.Decl3' requires the types 'Y' and 'X' be equivalent}}
45
45
let _ =SameType<Y>.Decl4<X>.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}}
46
46
let _ =SameType<Y>.Decl5<X>.self // expected-error {{'SameType<Y>.Decl5' requires the types 'Y' and 'X' be equivalent}}
47
47
48
-
extensionSameType:AssociatedTypewhere T ==X{} // expected-note {{where 'T' = 'Y'}}
49
-
50
-
// (Y first here, because there were issues caused by running associated type
51
-
// inference for the first time)
52
-
let _ =SameType<Y>.T.self // expected-error {{referencing type alias 'T' on 'SameType' requires the types 'Y' and 'X' be equivalent}}
48
+
extensionSameType:AssociatedTypewhere T ==X{}
49
+
// expected-note@-1 {{requirement specified as 'T' == 'X' [with T = Y]}}
53
50
54
51
let _ =SameType<X>.T.self
52
+
let _ =SameType<Y>.T.self // expected-error {{'SameType<Y>.T' (aka 'X') requires the types 'Y' and 'X' be equivalent}}
typealiasTypeAlias3<U>=(T,U) // expected-note {{requirement specified as 'T' == 'X' [with T = Y]}}
97
+
typealiasTypeAlias3<U>=(T,U)
99
98
100
99
structDecl1{}
101
100
enumDecl2{}
102
101
classDecl3{}
103
-
structDecl4<U>{} // expected-note {{requirement specified as 'T' == 'X' [with T = Y]}}
104
-
enumDecl5<U:P>{} // expected-note {{requirement specified as 'T' == 'X' [with T = Y]}}
102
+
structDecl4<U>{}
103
+
enumDecl5<U:P>{}
105
104
}
106
105
107
106
let _ =SameType<X>.Decl1.TypeAlias1.self
@@ -113,16 +112,16 @@ let _ = SameType<X>.Decl1.Decl3.self
113
112
let _ =SameType<X>.Decl1.Decl4<X>.self
114
113
let _ =SameType<X>.Decl1.Decl5<X>.self
115
114
116
-
let _ =SameType<Y>.Decl1.TypeAlias1.self // expected-error {{referencing type alias 'TypeAlias1' on 'SameType.Decl1' requires the types 'Y' and 'X' be equivalent}}
117
-
let _ =SameType<Y>.Decl1.TypeAlias2.self // expected-error {{referencing type alias 'TypeAlias2' on 'SameType.Decl1' requires the types 'Y' and 'X' be equivalent}}
118
-
let _ =SameType<Y>.Decl1.TypeAlias3<X>.self // expected-error {{'SameType<Y>.Decl1.TypeAlias3' requires the types 'Y' and 'X' be equivalent}}
119
-
let _ =SameType<Y>.Decl1.Decl1.self // expected-error {{referencing struct 'Decl1' on 'SameType.Decl1' requires the types 'Y' and 'X' be equivalent}}
120
-
let _ =SameType<Y>.Decl1.Decl2.self // expected-error {{referencing enum 'Decl2' on 'SameType.Decl1' requires the types 'Y' and 'X' be equivalent}}
121
-
let _ =SameType<Y>.Decl1.Decl3.self // expected-error {{referencing class 'Decl3' on 'SameType.Decl1' requires the types 'Y' and 'X' be equivalent}}
122
-
let _ =SameType<Y>.Decl1.Decl4<X>.self // expected-error {{'SameType<Y>.Decl1.Decl4' requires the types 'Y' and 'X' be equivalent}}
123
-
let _ =SameType<Y>.Decl1.Decl5<X>.self // expected-error {{'SameType<Y>.Decl1.Decl5' requires the types 'Y' and 'X' be equivalent}}
115
+
let _ =SameType<Y>.Decl1.TypeAlias1.self // expected-error {{'SameType<Y>.Decl1' requires the types 'Y' and 'X' be equivalent}}
116
+
let _ =SameType<Y>.Decl1.TypeAlias2.self // expected-error {{'SameType<Y>.Decl1' requires the types 'Y' and 'X' be equivalent}}
117
+
let _ =SameType<Y>.Decl1.TypeAlias3<X>.self // expected-error {{'SameType<Y>.Decl1' requires the types 'Y' and 'X' be equivalent}}
118
+
let _ =SameType<Y>.Decl1.Decl1.self // expected-error {{'SameType<Y>.Decl1' requires the types 'Y' and 'X' be equivalent}}
119
+
let _ =SameType<Y>.Decl1.Decl2.self // expected-error {{'SameType<Y>.Decl1' requires the types 'Y' and 'X' be equivalent}}
120
+
let _ =SameType<Y>.Decl1.Decl3.self // expected-error {{'SameType<Y>.Decl1' requires the types 'Y' and 'X' be equivalent}}
121
+
let _ =SameType<Y>.Decl1.Decl4<X>.self // expected-error {{'SameType<Y>.Decl1' requires the types 'Y' and 'X' be equivalent}}
122
+
let _ =SameType<Y>.Decl1.Decl5<X>.self // expected-error {{'SameType<Y>.Decl1' requires the types 'Y' and 'X' be equivalent}}
124
123
125
-
extensionSameType.Decl4where U ==X{ // expected-note 5 {{where 'U' = 'Y'}}
124
+
extensionSameType.Decl4where U ==X{ // expected-note 5 {{requirement specified as 'U' == 'X' [with U = Y]}}
126
125
typealiasTypeAlias1=T
127
126
typealiasTypeAlias2=Y
128
127
typealiasTypeAlias3<V>=(T,U,V) // expected-note {{requirement specified as 'U' == 'X' [with U = Y]}}
@@ -145,12 +144,12 @@ let _ = SameType<X>.Decl4<X>.Decl3.self
145
144
let _ =SameType<X>.Decl4<X>.Decl4<X>.self
146
145
let _ =SameType<X>.Decl4<X>.Decl5<X>.self
147
146
148
-
let _ =SameType<X>.Decl4<Y>.TypeAlias1.self // expected-error {{referencing type alias 'TypeAlias1' on 'SameType.Decl4' requires the types 'Y' and 'X' be equivalent}}
149
-
let _ =SameType<X>.Decl4<Y>.TypeAlias2.self // expected-error {{referencing type alias 'TypeAlias2' on 'SameType.Decl4' requires the types 'Y' and 'X' be equivalent}}
147
+
let _ =SameType<X>.Decl4<Y>.TypeAlias1.self // expected-error {{'SameType<X>.Decl4<Y>.TypeAlias1' (aka 'X') requires the types 'Y' and 'X' be equivalent}}
148
+
let _ =SameType<X>.Decl4<Y>.TypeAlias2.self // expected-error {{'SameType<X>.Decl4<Y>.TypeAlias2' (aka 'Y') requires the types 'Y' and 'X' be equivalent}}
150
149
let _ =SameType<X>.Decl4<Y>.TypeAlias3<X>.self // expected-error {{'SameType<X>.Decl4<Y>.TypeAlias3' requires the types 'Y' and 'X' be equivalent}}
151
-
let _ =SameType<X>.Decl4<Y>.Decl1.self // expected-error {{referencing struct 'Decl1' on 'SameType.Decl4' requires the types 'Y' and 'X' be equivalent}}
152
-
let _ =SameType<X>.Decl4<Y>.Decl2.self // expected-error {{referencing enum 'Decl2' on 'SameType.Decl4' requires the types 'Y' and 'X' be equivalent}}
153
-
let _ =SameType<X>.Decl4<Y>.Decl3.self // expected-error {{referencing class 'Decl3' on 'SameType.Decl4' requires the types 'Y' and 'X' be equivalent}}
150
+
let _ =SameType<X>.Decl4<Y>.Decl1.self // expected-error {{'SameType<X>.Decl4<Y>.Decl1' requires the types 'Y' and 'X' be equivalent}}
151
+
let _ =SameType<X>.Decl4<Y>.Decl2.self // expected-error {{'SameType<X>.Decl4<Y>.Decl2' requires the types 'Y' and 'X' be equivalent}}
152
+
let _ =SameType<X>.Decl4<Y>.Decl3.self // expected-error {{'SameType<X>.Decl4<Y>.Decl3' requires the types 'Y' and 'X' be equivalent}}
154
153
let _ =SameType<X>.Decl4<Y>.Decl4<X>.self // expected-error {{'SameType<X>.Decl4<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}}
155
154
let _ =SameType<X>.Decl4<Y>.Decl5<X>.self // expected-error {{'SameType<X>.Decl4<Y>.Decl5' requires the types 'Y' and 'X' be equivalent}}
@@ -200,34 +196,29 @@ let _ = Conforms<X>.Decl4<Z1>.Decl5<X>.self
200
196
// Two different forms of badness, corresponding to the two requirements:
201
197
202
198
let _ =Conforms<X>.Decl4<Y>.TypeAlias1.self
203
-
// expected-error@-1 {{referencing type alias 'TypeAlias1' on 'Conforms.Decl4' requires that 'Y.T' conform to 'P'}}
204
-
// expected-error@-2 {{referencing type alias 'TypeAlias1' on 'Conforms.Decl4' requires that 'Y' conform to 'AssociatedType'}}
199
+
// expected-error@-1 {{type 'Y' does not conform to protocol 'AssociatedType'}}
205
200
206
201
let _ =Conforms<X>.Decl4<Y>.TypeAlias2.self
207
-
// expected-error@-1 {{referencing type alias 'TypeAlias2' on 'Conforms.Decl4' requires that 'Y.T' conform to 'P'}}
208
-
// expected-error@-2 {{referencing type alias 'TypeAlias2' on 'Conforms.Decl4' requires that 'Y' conform to 'AssociatedType'}}
202
+
// expected-error@-1 {{type 'Y' does not conform to protocol 'AssociatedType'}}
209
203
210
204
let _ =Conforms<X>.Decl4<Y>.TypeAlias3<X>.self // expected-error {{type 'Y' does not conform to protocol 'AssociatedType'}}
211
205
let _ =Conforms<X>.Decl4<Y>.Decl1.self
212
-
// expected-error@-1 {{referencing struct 'Decl1' on 'Conforms.Decl4' requires that 'Y.T' conform to 'P'}}
213
-
// expected-error@-2 {{referencing struct 'Decl1' on 'Conforms.Decl4' requires that 'Y' conform to 'AssociatedType'}}
206
+
// expected-error@-1 {{type 'Y' does not conform to protocol 'AssociatedType'}}
214
207
215
208
let _ =Conforms<X>.Decl4<Y>.Decl2.self
216
-
// expected-error@-1 {{referencing enum 'Decl2' on 'Conforms.Decl4' requires that 'Y.T' conform to 'P'}}
217
-
// expected-error@-2 {{referencing enum 'Decl2' on 'Conforms.Decl4' requires that 'Y' conform to 'AssociatedType'}}
209
+
// expected-error@-1 {{type 'Y' does not conform to protocol 'AssociatedType'}}
218
210
219
211
let _ =Conforms<X>.Decl4<Y>.Decl3.self
220
-
// expected-error@-1 {{referencing class 'Decl3' on 'Conforms.Decl4' requires that 'Y.T' conform to 'P'}}
221
-
// expected-error@-2 {{referencing class 'Decl3' on 'Conforms.Decl4' requires that 'Y' conform to 'AssociatedType'}}
212
+
// expected-error@-1 {{type 'Y' does not conform to protocol 'AssociatedType'}}
222
213
223
214
let _ =Conforms<X>.Decl4<Y>.Decl4<X>.self // expected-error {{type 'Y' does not conform to protocol 'AssociatedType'}}
224
215
let _ =Conforms<X>.Decl4<Y>.Decl5<X>.self // expected-error {{type 'Y' does not conform to protocol 'AssociatedType'}}
225
216
226
-
let _ =Conforms<X>.Decl4<Z2>.TypeAlias1.self // expected-error {{referencing type alias 'TypeAlias1' on 'Conforms.Decl4' requires that 'Z2.T' (aka 'Y') conform to 'P'}}
227
-
let _ =Conforms<X>.Decl4<Z2>.TypeAlias2.self // expected-error {{referencing type alias 'TypeAlias2' on 'Conforms.Decl4' requires that 'Z2.T' (aka 'Y') conform to 'P'}}
217
+
let _ =Conforms<X>.Decl4<Z2>.TypeAlias1.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}}
218
+
let _ =Conforms<X>.Decl4<Z2>.TypeAlias2.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}}
228
219
let _ =Conforms<X>.Decl4<Z2>.TypeAlias3<X>.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}}
229
-
let _ =Conforms<X>.Decl4<Z2>.Decl1.self // expected-error {{referencing struct 'Decl1' on 'Conforms.Decl4' requires that 'Z2.T' (aka 'Y') conform to 'P'}}
230
-
let _ =Conforms<X>.Decl4<Z2>.Decl2.self // expected-error {{referencing enum 'Decl2' on 'Conforms.Decl4' requires that 'Z2.T' (aka 'Y') conform to 'P'}}
231
-
let _ =Conforms<X>.Decl4<Z2>.Decl3.self // expected-error {{referencing class 'Decl3' on 'Conforms.Decl4' requires that 'Z2.T' (aka 'Y') conform to 'P'}}
220
+
let _ =Conforms<X>.Decl4<Z2>.Decl1.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}}
221
+
let _ =Conforms<X>.Decl4<Z2>.Decl2.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}}
222
+
let _ =Conforms<X>.Decl4<Z2>.Decl3.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}}
232
223
let _ =Conforms<X>.Decl4<Z2>.Decl4<X>.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}}
233
224
let _ =Conforms<X>.Decl4<Z2>.Decl5<X>.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}}
0 commit comments