Skip to content

Commit d85b02c

Browse files
Suyash SrijanSuyash Srijan
authored andcommitted
[gsb] show a fixit if the subject type is a member type
1 parent ac78bbb commit d85b02c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5755,7 +5755,7 @@ GenericSignatureBuilder::finalize(SourceLoc loc,
57555755

57565756
// Emit a diagnostic if we recorded any constraints where the constraint
57575757
// type was not constrained to a protocol or class. Provide a fix-it if
5758-
// allowConcreteGenericParams is true.
5758+
// allowConcreteGenericParams is true or the subject type is a member type.
57595759
if (!invalidConstraints.empty()) {
57605760
for (auto constraint : invalidConstraints) {
57615761
auto loc = constraint.sourceLoc;
@@ -5775,7 +5775,7 @@ GenericSignatureBuilder::finalize(SourceLoc loc,
57755775
return subjectTypeName;
57765776
};
57775777

5778-
if (allowConcreteGenericParams) {
5778+
if (allowConcreteGenericParams || subjectType->is<DependentMemberType>()) {
57795779
auto subjectTypeName = subjectType.getString();
57805780
auto subjectTypeNameWithoutSelf = getNameWithoutSelf(subjectTypeName);
57815781
Diags.diagnose(loc,

test/Constraints/generics.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,3 +662,6 @@ protocol SR_7984_HasAssoc {
662662
struct SR_7984_X<T: SR_7984_HasAssoc> {}
663663
extension SR_7984_X where T.Assoc.Foo: String {} // expected-error {{type 'T.Assoc.Foo' constrained to non-protocol, non-class type 'String'}} // expected-note {{use 'T.Assoc.Foo == String' to require 'T.Assoc.Foo' to be 'String'}} {{38-39= ==}}
664664

665+
struct S<T: Sequence> where T.Element: String {} // expected-error {{type 'T.Element' constrained to non-protocol, non-class type 'String'}} expected-note {{use 'T.Element == String' to require 'T.Element' to be 'String'}} {{38-39= ==}}
666+
func F<T: Sequence>(foo: T) where T.Element: String {} // expected-error {{type 'T.Element' constrained to non-protocol, non-class type 'String'}} expected-note {{use 'T.Element == String' to require 'T.Element' to be 'String'}} {{44-45= ==}}
667+

0 commit comments

Comments
 (0)