Skip to content

Commit e4da7a1

Browse files
committed
[ConstraintSystem] Look through metatype of base while diagnosing conformance failures
Having `.Type` in `requires conformance` diagnostic is unnecessary.
1 parent 9d50122 commit e4da7a1

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8162,7 +8162,7 @@ bool ConstraintSystem::applySolutionFix(
81628162
auto conformance = getMissingConformance(locator);
81638163

81648164
auto *anchor = locator->getAnchor();
8165-
auto owner = solution.simplifyType(getType(anchor));
8165+
auto owner = solution.simplifyType(getType(anchor))->getRValueInstanceType();
81668166

81678167
auto type = conformance.first;
81688168
auto protocolType = conformance.second->getDeclaredType();

test/Constraints/conditionally_defined_types.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ let _ = Conforms<X>.Decl3.self
7575
let _ = Conforms<X>.Decl4<X>.self
7676
let _ = Conforms<X>.Decl5<X>.self
7777

78-
let _ = Conforms<Y>.TypeAlias1.self // expected-error {{'Conforms<Y>.TypeAlias1.Type' (aka 'Y.Type') requires that 'Y' conform to 'P'}}
79-
let _ = Conforms<Y>.TypeAlias2.self // expected-error {{'Conforms<Y>.TypeAlias2.Type' (aka 'Y.Type') requires that 'Y' conform to 'P'}}
78+
let _ = Conforms<Y>.TypeAlias1.self // expected-error {{'Conforms<Y>.TypeAlias1' (aka 'Y') requires that 'Y' conform to 'P'}}
79+
let _ = Conforms<Y>.TypeAlias2.self // expected-error {{'Conforms<Y>.TypeAlias2' (aka 'Y') requires that 'Y' conform to 'P'}}
8080
let _ = Conforms<Y>.TypeAlias3<X>.self // expected-error {{type 'Y' does not conform to protocol 'P'}}
81-
let _ = Conforms<Y>.Decl1.self // expected-error {{'Conforms<Y>.Decl1.Type' requires that 'Y' conform to 'P'}}
82-
let _ = Conforms<Y>.Decl2.self // expected-error {{'Conforms<Y>.Decl2.Type' requires that 'Y' conform to 'P'}}
83-
let _ = Conforms<Y>.Decl3.self // expected-error {{'Conforms<Y>.Decl3.Type' requires that 'Y' conform to 'P'}}
81+
let _ = Conforms<Y>.Decl1.self // expected-error {{'Conforms<Y>.Decl1' requires that 'Y' conform to 'P'}}
82+
let _ = Conforms<Y>.Decl2.self // expected-error {{'Conforms<Y>.Decl2' requires that 'Y' conform to 'P'}}
83+
let _ = Conforms<Y>.Decl3.self // expected-error {{'Conforms<Y>.Decl3' requires that 'Y' conform to 'P'}}
8484
let _ = Conforms<Y>.Decl4<X>.self // expected-error {{type 'Y' does not conform to protocol 'P'}}
8585
let _ = Conforms<Y>.Decl5<X>.self // expected-error {{type 'Y' does not conform to protocol 'P'}}
8686

8787
extension Conforms: AssociatedType where T: P {}
8888

89-
let _ = Conforms<Y>.T.self // expected-error {{'Conforms<Y>.T.Type' (aka 'Y.Type') requires that 'Y' conform to 'P'}}
89+
let _ = Conforms<Y>.T.self // expected-error {{'Conforms<Y>.T' (aka 'Y') requires that 'Y' conform to 'P'}}
9090

9191
let _ = Conforms<X>.T.self
9292

@@ -197,34 +197,34 @@ let _ = Conforms<X>.Decl4<Z1>.Decl5<X>.self
197197
// Two different forms of badness, corresponding to the two requirements:
198198

199199
let _ = Conforms<X>.Decl4<Y>.TypeAlias1.self
200-
// expected-error@-1 {{'Conforms<X>.Decl4<Y>.TypeAlias1.Type' (aka 'X.Type') requires that 'Y.T' conform to 'P'}}
201-
// expected-error@-2 {{'Conforms<X>.Decl4<Y>.TypeAlias1.Type' (aka 'X.Type') requires that 'Y' conform to 'AssociatedType'}}
200+
// expected-error@-1 {{'Conforms<X>.Decl4<Y>.TypeAlias1' (aka 'X') requires that 'Y.T' conform to 'P'}}
201+
// expected-error@-2 {{'Conforms<X>.Decl4<Y>.TypeAlias1' (aka 'X') requires that 'Y' conform to 'AssociatedType'}}
202202

203203
let _ = Conforms<X>.Decl4<Y>.TypeAlias2.self
204-
// expected-error@-1 {{'Conforms<X>.Decl4<Y>.TypeAlias2.Type' (aka 'Y.Type') requires that 'Y.T' conform to 'P'}}
205-
// expected-error@-2 {{'Conforms<X>.Decl4<Y>.TypeAlias2.Type' (aka 'Y.Type') requires that 'Y' conform to 'AssociatedType'}}
204+
// expected-error@-1 {{'Conforms<X>.Decl4<Y>.TypeAlias2' (aka 'Y') requires that 'Y.T' conform to 'P'}}
205+
// expected-error@-2 {{'Conforms<X>.Decl4<Y>.TypeAlias2' (aka 'Y') requires that 'Y' conform to 'AssociatedType'}}
206206

207207
let _ = Conforms<X>.Decl4<Y>.TypeAlias3<X>.self // expected-error {{type 'Y' does not conform to protocol 'AssociatedType'}}
208208
let _ = Conforms<X>.Decl4<Y>.Decl1.self
209-
// expected-error@-1 {{'Conforms<X>.Decl4<Y>.Decl1.Type' requires that 'Y.T' conform to 'P'}}
210-
// expected-error@-2 {{'Conforms<X>.Decl4<Y>.Decl1.Type' requires that 'Y' conform to 'AssociatedType'}}
209+
// expected-error@-1 {{'Conforms<X>.Decl4<Y>.Decl1' requires that 'Y.T' conform to 'P'}}
210+
// expected-error@-2 {{'Conforms<X>.Decl4<Y>.Decl1' requires that 'Y' conform to 'AssociatedType'}}
211211

212212
let _ = Conforms<X>.Decl4<Y>.Decl2.self
213-
// expected-error@-1 {{'Conforms<X>.Decl4<Y>.Decl2.Type' requires that 'Y.T' conform to 'P'}}
214-
// expected-error@-2 {{'Conforms<X>.Decl4<Y>.Decl2.Type' requires that 'Y' conform to 'AssociatedType'}}
213+
// expected-error@-1 {{'Conforms<X>.Decl4<Y>.Decl2' requires that 'Y.T' conform to 'P'}}
214+
// expected-error@-2 {{'Conforms<X>.Decl4<Y>.Decl2' requires that 'Y' conform to 'AssociatedType'}}
215215

216216
let _ = Conforms<X>.Decl4<Y>.Decl3.self
217-
// expected-error@-1 {{'Conforms<X>.Decl4<Y>.Decl3.Type' requires that 'Y.T' conform to 'P'}}
218-
// expected-error@-2 {{'Conforms<X>.Decl4<Y>.Decl3.Type' requires that 'Y' conform to 'AssociatedType'}}
217+
// expected-error@-1 {{'Conforms<X>.Decl4<Y>.Decl3' requires that 'Y.T' conform to 'P'}}
218+
// expected-error@-2 {{'Conforms<X>.Decl4<Y>.Decl3' requires that 'Y' conform to 'AssociatedType'}}
219219

220220
let _ = Conforms<X>.Decl4<Y>.Decl4<X>.self // expected-error {{type 'Y' does not conform to protocol 'AssociatedType'}}
221221
let _ = Conforms<X>.Decl4<Y>.Decl5<X>.self // expected-error {{type 'Y' does not conform to protocol 'AssociatedType'}}
222222

223-
let _ = Conforms<X>.Decl4<Z2>.TypeAlias1.self // expected-error {{'Conforms<X>.Decl4<Z2>.TypeAlias1.Type' (aka 'X.Type') requires that 'Z2.T' (aka 'Y') conform to 'P'}}
224-
let _ = Conforms<X>.Decl4<Z2>.TypeAlias2.self // expected-error {{'Conforms<X>.Decl4<Z2>.TypeAlias2.Type' (aka 'Y.Type') requires that 'Z2.T' (aka 'Y') conform to 'P'}}
223+
let _ = Conforms<X>.Decl4<Z2>.TypeAlias1.self // expected-error {{'Conforms<X>.Decl4<Z2>.TypeAlias1' (aka 'X') requires that 'Z2.T' (aka 'Y') conform to 'P'}}
224+
let _ = Conforms<X>.Decl4<Z2>.TypeAlias2.self // expected-error {{'Conforms<X>.Decl4<Z2>.TypeAlias2' (aka 'Y') requires that 'Z2.T' (aka 'Y') conform to 'P'}}
225225
let _ = Conforms<X>.Decl4<Z2>.TypeAlias3<X>.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}}
226-
let _ = Conforms<X>.Decl4<Z2>.Decl1.self // expected-error {{'Conforms<X>.Decl4<Z2>.Decl1.Type' requires that 'Z2.T' (aka 'Y') conform to 'P'}}
227-
let _ = Conforms<X>.Decl4<Z2>.Decl2.self // expected-error {{'Conforms<X>.Decl4<Z2>.Decl2.Type' requires that 'Z2.T' (aka 'Y') conform to 'P'}}
228-
let _ = Conforms<X>.Decl4<Z2>.Decl3.self // expected-error {{'Conforms<X>.Decl4<Z2>.Decl3.Type' requires that 'Z2.T' (aka 'Y') conform to 'P'}}
226+
let _ = Conforms<X>.Decl4<Z2>.Decl1.self // expected-error {{'Conforms<X>.Decl4<Z2>.Decl1' requires that 'Z2.T' (aka 'Y') conform to 'P'}}
227+
let _ = Conforms<X>.Decl4<Z2>.Decl2.self // expected-error {{'Conforms<X>.Decl4<Z2>.Decl2' requires that 'Z2.T' (aka 'Y') conform to 'P'}}
228+
let _ = Conforms<X>.Decl4<Z2>.Decl3.self // expected-error {{'Conforms<X>.Decl4<Z2>.Decl3' requires that 'Z2.T' (aka 'Y') conform to 'P'}}
229229
let _ = Conforms<X>.Decl4<Z2>.Decl4<X>.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}}
230230
let _ = Conforms<X>.Decl4<Z2>.Decl5<X>.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}}

test/Constraints/rdar39931339.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ class B<U> : A<[U], U> {}
2929

3030
_ = B<C>.S1() // Ok
3131
_ = B<Int>.S2() // Ok
32-
_ = B<Float>.S1() // expected-error {{'B<Float>.S1.Type' (aka 'Int.Type') requires that 'Float' conform to 'P'}}
32+
_ = B<Float>.S1() // expected-error {{'B<Float>.S1' (aka 'Int') requires that 'Float' conform to 'P'}}
3333
_ = B<String>.S2() // expected-error {{'B<String>.S2.Type' (aka 'Int.Type') requires the types '[String]' and '[Int]' be equivalent}}
3434

3535
_ = S<C>.A() // Ok
36-
_ = S<Int>.A() // expected-error {{'S<Int>.A.Type' (aka 'Int.Type') requires that 'Int' conform to 'P'}}
36+
_ = S<Int>.A() // expected-error {{'S<Int>.A' (aka 'Int') requires that 'Int' conform to 'P'}}
3737
_ = S<String>.B<Int>() // expected-error {{type 'String' does not conform to protocol 'P'}}
3838
_ = S<Int>.C() // expected-error {{'S<Int>.C.Type' (aka 'Int.Type') requires the types 'Int' and 'Float' be equivalent}}
3939

4040
func foo<T>(_ s: S<T>.Type) {
41-
_ = s.A() // expected-error {{'S<T>.A.Type' (aka 'Int.Type') requires that 'T' conform to 'P'}}
41+
_ = s.A() // expected-error {{'S<T>.A' (aka 'Int') requires that 'T' conform to 'P'}}
4242
}
4343

4444
func bar<T: P>(_ s: S<T>.Type) {

0 commit comments

Comments
 (0)