@@ -128,12 +128,14 @@ static void desugarSuperclassRequirement(Type subjectType,
128
128
SmallVectorImpl<Requirement> &result,
129
129
SmallVectorImpl<RequirementError> &errors) {
130
130
if (!subjectType->isTypeParameter ()) {
131
+ Requirement requirement (RequirementKind::Superclass,
132
+ subjectType, constraintType);
131
133
if (constraintType->isExactSuperclassOf (subjectType)) {
132
- errors.push_back (RequirementError::forRedundantRequirement (
133
- {RequirementKind::Superclass, subjectType, constraintType} , loc));
134
+ errors.push_back (
135
+ RequirementError::forRedundantRequirement (requirement , loc));
134
136
} else {
135
137
errors.push_back (
136
- RequirementError::forNonTypeParameter (subjectType , loc));
138
+ RequirementError::forNonTypeParameter (requirement , loc));
137
139
}
138
140
139
141
return ;
@@ -148,12 +150,14 @@ static void desugarLayoutRequirement(Type subjectType,
148
150
SmallVectorImpl<Requirement> &result,
149
151
SmallVectorImpl<RequirementError> &errors) {
150
152
if (!subjectType->isTypeParameter ()) {
153
+ Requirement requirement (RequirementKind::Layout,
154
+ subjectType, layout);
151
155
if (subjectType->isAnyClassReferenceType ()) {
152
- errors.push_back (RequirementError::forRedundantRequirement (
153
- {RequirementKind::Layout, subjectType, layout} , loc));
156
+ errors.push_back (
157
+ RequirementError::forRedundantRequirement (requirement , loc));
154
158
} else {
155
159
errors.push_back (
156
- RequirementError::forNonTypeParameter (subjectType , loc));
160
+ RequirementError::forNonTypeParameter (requirement , loc));
157
161
}
158
162
159
163
return ;
@@ -189,8 +193,8 @@ static void desugarConformanceRequirement(Type subjectType, Type constraintType,
189
193
auto *module = protoDecl->getParentModule ();
190
194
auto conformance = module ->lookupConformance (subjectType, protoDecl);
191
195
if (conformance.isInvalid ()) {
192
- errors.push_back (
193
- RequirementError::forNonTypeParameter ( subjectType, loc));
196
+ errors.push_back (RequirementError::forNonTypeParameter (
197
+ {RequirementKind::Conformance, subjectType, constraintType} , loc));
194
198
return ;
195
199
}
196
200
@@ -541,8 +545,8 @@ bool swift::rewriting::diagnoseRequirementErrors(
541
545
542
546
switch (error.kind ) {
543
547
case RequirementError::Kind::InvalidConformance: {
544
- Type subjectType = error.invalidConformance . subjectType ;
545
- Type constraint = error.invalidConformance . constraint ;
548
+ Type subjectType = error.requirement . getFirstType () ;
549
+ Type constraint = error.requirement . getSecondType () ;
546
550
547
551
// FIXME: The constraint string is printed directly here because
548
552
// the current default is to not print `any` for existential
@@ -578,8 +582,8 @@ bool swift::rewriting::diagnoseRequirementErrors(
578
582
}
579
583
580
584
case RequirementError::Kind::ConcreteTypeMismatch: {
581
- auto type1 = error.concreteTypeMismatch . type1 ;
582
- auto type2 = error.concreteTypeMismatch . type2 ;
585
+ auto type1 = error.requirement . getFirstType () ;
586
+ auto type2 = error.requirement . getSecondType () ;
583
587
584
588
if (!type1->hasError () && !type2->hasError ()) {
585
589
ctx.Diags .diagnose (loc, diag::requires_same_concrete_type,
@@ -592,13 +596,13 @@ bool swift::rewriting::diagnoseRequirementErrors(
592
596
593
597
case RequirementError::Kind::NonTypeParameter: {
594
598
ctx.Diags .diagnose (loc, diag::requires_not_suitable_archetype,
595
- error.nonTypeParameter );
599
+ error.requirement . getFirstType () );
596
600
diagnosedError = true ;
597
601
break ;
598
602
}
599
603
600
604
case RequirementError::Kind::RedundantRequirement: {
601
- auto requirement = error.redundantRequirement ;
605
+ auto requirement = error.requirement ;
602
606
switch (requirement.getKind ()) {
603
607
case RequirementKind::SameType:
604
608
ctx.Diags .diagnose (loc, diag::redundant_same_type_to_concrete,
0 commit comments