@@ -54,17 +54,19 @@ using namespace rewriting;
54
54
// / Desugar a same-type requirement that possibly has concrete types on either
55
55
// / side into a series of same-type and concrete-type requirements where the
56
56
// / left hand side is always a type parameter.
57
- static void desugarSameTypeRequirement (Type lhs, Type rhs,
57
+ static void desugarSameTypeRequirement (Type lhs, Type rhs, SourceLoc loc,
58
58
SmallVectorImpl<Requirement> &result,
59
59
SmallVectorImpl<RequirementError> &errors) {
60
60
class Matcher : public TypeMatcher <Matcher> {
61
+ SourceLoc loc;
61
62
SmallVectorImpl<Requirement> &result;
62
63
SmallVectorImpl<RequirementError> &errors;
63
64
64
65
public:
65
- explicit Matcher (SmallVectorImpl<Requirement> &result,
66
+ explicit Matcher (SourceLoc loc,
67
+ SmallVectorImpl<Requirement> &result,
66
68
SmallVectorImpl<RequirementError> &errors)
67
- : result(result), errors(errors) {}
69
+ : loc(loc), result(result), errors(errors) {}
68
70
69
71
bool mismatch (TypeBase *firstType, TypeBase *secondType,
70
72
Type sugaredFirstType) {
@@ -86,10 +88,13 @@ static void desugarSameTypeRequirement(Type lhs, Type rhs,
86
88
return true ;
87
89
}
88
90
89
- // FIXME: Record concrete type conflict, diagnose upstream
91
+ errors.push_back (
92
+ RequirementError::forConcreteTypeMismatch (firstType,
93
+ secondType,
94
+ loc));
90
95
return true ;
91
96
}
92
- } matcher (result, errors);
97
+ } matcher (loc, result, errors);
93
98
94
99
if (lhs->hasError () || rhs->hasError ())
95
100
return ;
@@ -178,7 +183,7 @@ static void desugarConformanceRequirement(Type subjectType, Type constraintType,
178
183
179
184
auto memberType = lookupMemberType (subjectType, protoDecl, assocType);
180
185
desugarSameTypeRequirement (memberType, paramType->getArgumentType (),
181
- result, errors);
186
+ SourceLoc (), result, errors);
182
187
return ;
183
188
}
184
189
@@ -226,7 +231,7 @@ swift::rewriting::desugarRequirement(Requirement req,
226
231
227
232
case RequirementKind::SameType:
228
233
desugarSameTypeRequirement (firstType, req.getSecondType (),
229
- result, errors);
234
+ SourceLoc (), result, errors);
230
235
break ;
231
236
}
232
237
}
@@ -443,7 +448,8 @@ void swift::rewriting::realizeRequirement(
443
448
}
444
449
445
450
SmallVector<Requirement, 2 > reqs;
446
- desugarSameTypeRequirement (req.getFirstType (), secondType, reqs, errors);
451
+ desugarSameTypeRequirement (req.getFirstType (), secondType, loc,
452
+ reqs, errors);
447
453
448
454
for (auto req : reqs)
449
455
result.push_back ({req, loc, /* wasInferred=*/ false });
@@ -488,6 +494,8 @@ void swift::rewriting::diagnoseRequirementErrors(
488
494
489
495
for (auto error : errors) {
490
496
SourceLoc loc = error.loc ;
497
+ if (!loc.isValid ())
498
+ continue ;
491
499
492
500
switch (error.kind ) {
493
501
case RequirementError::Kind::InvalidConformance: {
@@ -525,6 +533,18 @@ void swift::rewriting::diagnoseRequirementErrors(
525
533
526
534
break ;
527
535
}
536
+
537
+ case RequirementError::Kind::ConcreteTypeMismatch: {
538
+ auto type1 = error.concreteTypeMismatch .type1 ;
539
+ auto type2 = error.concreteTypeMismatch .type2 ;
540
+
541
+ if (!type1->hasError () && !type2->hasError ()) {
542
+ ctx.Diags .diagnose (loc, diag::requires_same_concrete_type,
543
+ type1, type2);
544
+ }
545
+
546
+ break ;
547
+ }
528
548
}
529
549
}
530
550
}
@@ -672,7 +692,7 @@ TypeAliasRequirementsRequest::evaluate(Evaluator &evaluator,
672
692
auto recordInheritedTypeRequirement = [&](TypeDecl *first, TypeDecl *second) {
673
693
desugarSameTypeRequirement (getStructuralType (first),
674
694
getStructuralType (second),
675
- result, errors);
695
+ SourceLoc (), result, errors);
676
696
};
677
697
678
698
// Local function to find the insertion point for the protocol's "where"
0 commit comments