@@ -105,10 +105,12 @@ static void desugarSameTypeRequirement(Type lhs, Type rhs, SourceLoc loc,
105
105
106
106
static void desugarSuperclassRequirement (Type subjectType,
107
107
Type constraintType,
108
+ SourceLoc loc,
108
109
SmallVectorImpl<Requirement> &result,
109
110
SmallVectorImpl<RequirementError> &errors) {
110
111
if (!subjectType->isTypeParameter ()) {
111
- // FIXME: Perform unification, diagnose redundancy or conflict upstream
112
+ errors.push_back (
113
+ RequirementError::forNonTypeParameter (subjectType, loc));
112
114
return ;
113
115
}
114
116
@@ -117,10 +119,12 @@ static void desugarSuperclassRequirement(Type subjectType,
117
119
118
120
static void desugarLayoutRequirement (Type subjectType,
119
121
LayoutConstraint layout,
122
+ SourceLoc loc,
120
123
SmallVectorImpl<Requirement> &result,
121
124
SmallVectorImpl<RequirementError> &errors) {
122
125
if (!subjectType->isTypeParameter ()) {
123
- // FIXME: Diagnose redundancy or conflict upstream
126
+ errors.push_back (
127
+ RequirementError::forNonTypeParameter (subjectType, loc));
124
128
return ;
125
129
}
126
130
@@ -143,6 +147,7 @@ static Type lookupMemberType(Type subjectType, ProtocolDecl *protoDecl,
143
147
// / compositions on the right hand side into conformance and superclass
144
148
// / requirements.
145
149
static void desugarConformanceRequirement (Type subjectType, Type constraintType,
150
+ SourceLoc loc,
146
151
SmallVectorImpl<Requirement> &result,
147
152
SmallVectorImpl<RequirementError> &errors) {
148
153
// Fast path.
@@ -153,7 +158,8 @@ static void desugarConformanceRequirement(Type subjectType, Type constraintType,
153
158
auto *module = protoDecl->getParentModule ();
154
159
auto conformance = module ->lookupConformance (subjectType, protoDecl);
155
160
if (conformance.isInvalid ()) {
156
- // FIXME: Diagnose a conflict.
161
+ errors.push_back (
162
+ RequirementError::forNonTypeParameter (subjectType, loc));
157
163
return ;
158
164
}
159
165
@@ -177,13 +183,13 @@ static void desugarConformanceRequirement(Type subjectType, Type constraintType,
177
183
auto *protoDecl = paramType->getBaseType ()->getDecl ();
178
184
179
185
desugarConformanceRequirement (subjectType, paramType->getBaseType (),
180
- result, errors);
186
+ loc, result, errors);
181
187
182
188
auto *assocType = protoDecl->getPrimaryAssociatedType ();
183
189
184
190
auto memberType = lookupMemberType (subjectType, protoDecl, assocType);
185
191
desugarSameTypeRequirement (memberType, paramType->getArgumentType (),
186
- SourceLoc () , result, errors);
192
+ loc , result, errors);
187
193
return ;
188
194
}
189
195
@@ -192,14 +198,16 @@ static void desugarConformanceRequirement(Type subjectType, Type constraintType,
192
198
desugarLayoutRequirement (subjectType,
193
199
LayoutConstraint::getLayoutConstraint (
194
200
LayoutConstraintKind::Class),
195
- result, errors);
201
+ loc, result, errors);
196
202
}
197
203
198
204
for (auto memberType : compositionType->getMembers ()) {
199
205
if (memberType->isExistentialType ())
200
- desugarConformanceRequirement (subjectType, memberType, result, errors);
206
+ desugarConformanceRequirement (subjectType, memberType,
207
+ loc, result, errors);
201
208
else
202
- desugarSuperclassRequirement (subjectType, memberType, result, errors);
209
+ desugarSuperclassRequirement (subjectType, memberType,
210
+ loc, result, errors);
203
211
}
204
212
}
205
213
@@ -216,17 +224,17 @@ swift::rewriting::desugarRequirement(Requirement req,
216
224
switch (req.getKind ()) {
217
225
case RequirementKind::Conformance:
218
226
desugarConformanceRequirement (firstType, req.getSecondType (),
219
- result, errors);
227
+ SourceLoc (), result, errors);
220
228
break ;
221
229
222
230
case RequirementKind::Superclass:
223
231
desugarSuperclassRequirement (firstType, req.getSecondType (),
224
- result, errors);
232
+ SourceLoc (), result, errors);
225
233
break ;
226
234
227
235
case RequirementKind::Layout:
228
236
desugarLayoutRequirement (firstType, req.getLayoutConstraint (),
229
- result, errors);
237
+ SourceLoc (), result, errors);
230
238
break ;
231
239
232
240
case RequirementKind::SameType:
@@ -252,10 +260,10 @@ static void realizeTypeRequirement(Type subjectType, Type constraintType,
252
260
253
261
if (constraintType->isConstraintType ()) {
254
262
// Handle conformance requirements.
255
- desugarConformanceRequirement (subjectType, constraintType, reqs, errors);
263
+ desugarConformanceRequirement (subjectType, constraintType, loc, reqs, errors);
256
264
} else if (constraintType->getClassOrBoundGenericClass ()) {
257
265
// Handle superclass requirements.
258
- desugarSuperclassRequirement (subjectType, constraintType, reqs, errors);
266
+ desugarSuperclassRequirement (subjectType, constraintType, loc, reqs, errors);
259
267
} else {
260
268
errors.push_back (
261
269
RequirementError::forInvalidConformance (subjectType,
@@ -427,7 +435,7 @@ void swift::rewriting::realizeRequirement(
427
435
428
436
SmallVector<Requirement, 2 > reqs;
429
437
desugarLayoutRequirement (firstType, req.getLayoutConstraint (),
430
- reqs, errors);
438
+ loc, reqs, errors);
431
439
432
440
for (auto req : reqs)
433
441
result.push_back ({req, loc, /* wasInferred=*/ false });
@@ -545,6 +553,12 @@ void swift::rewriting::diagnoseRequirementErrors(
545
553
546
554
break ;
547
555
}
556
+
557
+ case RequirementError::Kind::NonTypeParameter: {
558
+ ctx.Diags .diagnose (loc, diag::requires_not_suitable_archetype,
559
+ error.nonTypeParameter );
560
+ break ;
561
+ }
548
562
}
549
563
}
550
564
}
0 commit comments