Skip to content

Commit 55db916

Browse files
Suyash SrijanSuyash Srijan
authored andcommitted
[gsb] check if the subject type has an assoc type decl
1 parent 0bcdf75 commit 55db916

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5775,11 +5775,12 @@ GenericSignatureBuilder::finalize(SourceLoc loc,
57755775
return subjectTypeName;
57765776
};
57775777

5778-
if (allowConcreteGenericParams || subjectType->is<DependentMemberType>()) {
5778+
auto DMT = subjectType->getAs<DependentMemberType>();
5779+
5780+
if (allowConcreteGenericParams || (DMT && !DMT->getAssocType())) {
57795781
auto subjectTypeName = subjectType.getString();
57805782
auto subjectTypeNameWithoutSelf = getNameWithoutSelf(subjectTypeName);
5781-
Diags.diagnose(loc,
5782-
diag::requires_conformance_nonprotocol_fixit,
5783+
Diags.diagnose(loc, diag::requires_conformance_nonprotocol_fixit,
57835784
subjectTypeNameWithoutSelf, constraintType.getString())
57845785
.fixItReplace(loc, " == ");
57855786
}

test/Constraints/generics.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,3 +664,7 @@ extension SR_7984_X where T.Assoc.Foo: String {} // expected-error {{type 'T.Ass
664664

665665
struct SR_7984_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'}} {{46-47= ==}}
666666
func SR_7984_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'}} {{52-53= ==}}
667+
668+
protocol SR_7984_P {
669+
func S<T : Sequence>(bar: 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'}} {{47-48= ==}}
670+
}

test/NameBinding/scope_map_lookup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protocol P1 {
2626
protocol AProtocol {
2727
associatedtype e : e
2828
// expected-error@-1 {{inheritance from non-protocol, non-class type 'Self.e'}}
29-
// expected-error@-2 {{type 'Self.e' constrained to non-protocol, non-class type 'Self.e'}} expected-note@-2 {{use 'e == Self.e' to require 'e' to be 'Self.e'}} {{22-23===}}
29+
// expected-error@-2 {{type 'Self.e' constrained to non-protocol, non-class type 'Self.e'}}
3030
}
3131

3232
// Extensions.

test/Sema/circular_decl_checking.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var TopLevelVar: TopLevelVar? { return nil } // expected-error {{use of undeclar
4646
// FIXME: The first error is redundant and isn't correct in what it states.
4747
protocol AProtocol {
4848
associatedtype e : e
49-
// expected-error@-1 {{type 'Self.e' constrained to non-protocol, non-class type 'Self.e'}} expected-note@-1 {{use 'e == Self.e' to require 'e' to be 'Self.e'}} {{22-23===}}
49+
// expected-error@-1 {{type 'Self.e' constrained to non-protocol, non-class type 'Self.e'}}
5050
// expected-error@-2 {{inheritance from non-protocol, non-class type 'Self.e'}}
5151
}
5252

test/decl/protocol/req/unsatisfiable.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,24 @@ protocol Base {
4343
// same type.
4444
protocol Sub1: Base {
4545
associatedtype SubAssoc: Assoc
46-
// expected-error@-1 {{type 'Self.SubAssoc' constrained to non-protocol, non-class type 'Self.Assoc'}} expected-note@-1 {{use 'SubAssoc == Self.Assoc' to require 'SubAssoc' to be 'Self.Assoc'}} {{28-33===}}
46+
// expected-error@-1 {{type 'Self.SubAssoc' constrained to non-protocol, non-class type 'Self.Assoc'}}
4747
// expected-error@-2 {{inheritance from non-protocol, non-class type 'Self.Assoc'}}
4848
}
4949

5050
// FIXME: This error is incorrect in what it states.
5151
protocol Sub2: Base {
52-
associatedtype SubAssoc where SubAssoc: Assoc // expected-error {{type 'Self.SubAssoc' constrained to non-protocol, non-class type 'Self.Assoc'}} expected-note {{use 'SubAssoc == Self.Assoc' to require 'SubAssoc' to be 'Self.Assoc'}} {{41-42= ==}}
52+
associatedtype SubAssoc where SubAssoc: Assoc // expected-error {{type 'Self.SubAssoc' constrained to non-protocol, non-class type 'Self.Assoc'}}
5353
}
5454

5555
struct S {}
5656

5757
// FIX-ME: One of these errors is redundant.
5858
protocol P4 {
5959
associatedtype X : S
60-
// expected-error@-1 {{type 'Self.X' constrained to non-protocol, non-class type 'S'}} expected-note@-1 {{use 'X == S' to require 'X' to be 'S'}} {{22-23===}}
60+
// expected-error@-1 {{type 'Self.X' constrained to non-protocol, non-class type 'S'}}
6161
// expected-error@-2 {{inheritance from non-protocol, non-class type 'S'}}
6262
}
6363

6464
protocol P5 {
65-
associatedtype Y where Y : S // expected-error {{type 'Self.Y' constrained to non-protocol, non-class type 'S'}} expected-note {{use 'Y == S' to require 'Y' to be 'S'}} {{28-29===}}
65+
associatedtype Y where Y : S // expected-error {{type 'Self.Y' constrained to non-protocol, non-class type 'S'}}
6666
}

0 commit comments

Comments
 (0)