Skip to content

Commit 45d28aa

Browse files
Suyash SrijanSuyash Srijan
authored andcommitted
[gsb] emit diagnostic for protocols as well
1 parent 5be4975 commit 45d28aa

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4631,18 +4631,29 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
46314631
Impl->HadAnyError = true;
46324632

46334633
bool shouldOfferFixit = false;
4634-
if (auto GTPT = subjectType->getAs<GenericTypeParamType>()) {
4634+
auto DMT = subjectType->getAs<DependentMemberType>();
4635+
auto GTPT = subjectType->getAs<GenericTypeParamType>();
4636+
4637+
if (GTPT) {
46354638
shouldOfferFixit = isa<ExtensionDecl>(GTPT->getDecl()
46364639
->getDeclContext());
46374640
}
4638-
4641+
4642+
if (DMT) {
4643+
shouldOfferFixit = isa<ExtensionDecl>(DMT->getRootGenericParam()
4644+
->getDecl()
4645+
->getDeclContext());
4646+
}
4647+
46394648
if (shouldOfferFixit) {
4649+
auto subjectTypeName = DMT ? DMT->getName().str().str() :
4650+
subjectType.getString();
46404651
Diags.diagnose(source.getLoc(), diag::requires_conformance_nonprotocol,
46414652
subjectType, constraintType);
46424653
Diags.diagnose(source.getLoc(),
4643-
diag::requires_conformance_nonprotocol_fixit,
4644-
subjectType.getString(), constraintType.getString())
4645-
.fixItReplace(source.getLoc(), " == ");
4654+
diag::requires_conformance_nonprotocol_fixit,
4655+
subjectTypeName, constraintType.getString())
4656+
.fixItReplace(source.getLoc(), " == ");
46464657
} else {
46474658
Diags.diagnose(source.getLoc(), diag::requires_conformance_nonprotocol,
46484659
subjectType, constraintType);

test/Constraints/generics.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,3 +645,9 @@ struct SR_7984<Bar> {
645645
}
646646

647647
extension SR_7984 where Bar: String {} // expected-error {{type 'Bar' constrained to non-protocol, non-class type 'String'}} expected-note {{use 'Bar == String' to require 'Bar' to be 'String'}} {{28-29= ==}}
648+
649+
protocol Foo {
650+
associatedtype Bar
651+
}
652+
653+
extension Foo where Bar: String {} // expected-error {{type 'Self.Bar' constrained to non-protocol, non-class type 'String'}} // expected-note {{use 'Bar == String' to require 'Bar' to be 'String'}} {{24-25= ==}}

0 commit comments

Comments
 (0)