Skip to content

Commit a8698d7

Browse files
Suyash SrijanSuyash Srijan
authored andcommitted
[gsb] use requirement source
1 parent 55db916 commit a8698d7

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,11 @@ class GenericSignatureBuilder {
320320
struct InvalidConstraint {
321321
Type subjectType;
322322
Type constraintType;
323-
SourceLoc sourceLoc;
324-
323+
const RequirementSource *reqSource;
324+
325325
InvalidConstraint(const Type type1, const Type type2,
326-
const SourceLoc loc) : subjectType(type1),
327-
constraintType(type2),
328-
sourceLoc(loc) {}
326+
const RequirementSource *source)
327+
: subjectType(type1), constraintType(type2), reqSource(source) {}
329328
};
330329

331330
/// The set of constraints that are invalid because the constraint

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4629,9 +4629,9 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
46294629
->getDependentType(getGenericParams());
46304630

46314631
Impl->HadAnyError = true;
4632-
4633-
auto invalidConstraint = InvalidConstraint(subjectType, constraintType,
4634-
source.getLoc());
4632+
4633+
auto invalidConstraint = InvalidConstraint(
4634+
subjectType, constraintType, source.getSource(*this, subjectType));
46354635
invalidConstraints.push_back(invalidConstraint);
46364636
}
46374637

@@ -5758,10 +5758,11 @@ GenericSignatureBuilder::finalize(SourceLoc loc,
57585758
// allowConcreteGenericParams is true or the subject type is a member type.
57595759
if (!invalidConstraints.empty()) {
57605760
for (auto constraint : invalidConstraints) {
5761-
auto loc = constraint.sourceLoc;
57625761
auto subjectType = constraint.subjectType;
57635762
auto constraintType = constraint.constraintType;
5764-
5763+
auto source = constraint.reqSource;
5764+
auto loc = source->getLoc();
5765+
57655766
Diags.diagnose(loc, diag::requires_conformance_nonprotocol,
57665767
subjectType, constraintType);
57675768

@@ -5774,10 +5775,10 @@ GenericSignatureBuilder::finalize(SourceLoc loc,
57745775

57755776
return subjectTypeName;
57765777
};
5777-
5778-
auto DMT = subjectType->getAs<DependentMemberType>();
5779-
5780-
if (allowConcreteGenericParams || (DMT && !DMT->getAssocType())) {
5778+
5779+
if (allowConcreteGenericParams ||
5780+
(subjectType->is<DependentMemberType>() &&
5781+
!source->isProtocolRequirement())) {
57815782
auto subjectTypeName = subjectType.getString();
57825783
auto subjectTypeNameWithoutSelf = getNameWithoutSelf(subjectTypeName);
57835784
Diags.diagnose(loc, diag::requires_conformance_nonprotocol_fixit,

0 commit comments

Comments
 (0)