[Diagnostics] NFC: Adjust all diagnostics improved/changed by static member refs on protocol metatypes feature

This commit is contained in:
Pavel Yaskevich
2020-10-30 14:40:01 -07:00
parent feb8684dac
commit 30f255755b
4 changed files with 16 additions and 10 deletions

View File

@@ -6881,6 +6881,13 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
if (auto *fnType = resultTy->getAs<FunctionType>())
resultTy = fnType->getResult();
// No reason to suggest that `Void` doesn't conform to some protocol.
if (resultTy->isVoid()) {
result.addUnviable(candidate,
MemberLookupResult::UR_TypeMemberOnInstance);
return;
}
// If result is not a concrete type which could conform to the
// expected protocol, this method is only viable for diagnostics.
if (!(resultTy->is<NominalType>() || resultTy->is<BoundGenericType>()) ||

View File

@@ -32,7 +32,7 @@ protocol Whereable {
}
extension Whereable {
// expected-note@+1 {{where 'Self' = 'T1'}}
// expected-note@+1 {{'staticExtensionFunc(arg:)' declared here}}
static func staticExtensionFunc(arg: Self.Element) -> Self.Element
where Self: Sequence {
return arg
@@ -53,7 +53,7 @@ func testProtocolExtensions<T1, T2, T3, T4>(t1: T1, t2: T2, t3: T3, t4: T4)
T2: Whereable & Sequence,
T3: Whereable, T3.Assoc == T3.Bssoc,
T4: Whereable, T4.Assoc: Whereable {
_ = T1.staticExtensionFunc // expected-error {{static method 'staticExtensionFunc(arg:)' requires that 'T1' conform to 'Sequence'}}
_ = T1.staticExtensionFunc // expected-error {{cannot reference static method 'staticExtensionFunc(arg:)' on 'Whereable.Protocol' with non-conforming result type '_.Element'}}
_ = T2.staticExtensionFunc
t1.extensionFunc() // expected-error {{instance method 'extensionFunc()' requires the types 'T1.Assoc' and 'T1.Bssoc' be equivalent}}

View File

@@ -197,8 +197,8 @@ extension AnotherBazProtocol where BazValue: AnotherBazProtocol {} // ok, does n
// Protocol extensions with additional requirements
// ----------------------------------------------------------------------------
extension P4 where Self.AssocP4 : P1 {
// expected-note@-1 {{candidate requires that 'Int' conform to 'P1' (requirement specified as 'Self.AssocP4' == 'P1')}}
// expected-note@-2 {{candidate requires that 'S4aHelper' conform to 'P1' (requirement specified as 'Self.AssocP4' == 'P1')}}
// expected-note@-1 {{where 'Self.AssocP4' = 'Int'}}
// expected-note@-2 {{where 'Self.AssocP4' = 'S4aHelper'}}
func extP4a() {
acceptsP1(reqP4a())
}
@@ -230,15 +230,13 @@ extension P4 where Self.AssocP4 == Int { // expected-note {{where 'Self.AssocP4'
}
extension P4 where Self.AssocP4 == Bool {
// expected-note@-1 {{candidate requires that the types 'Int' and 'Bool' be equivalent (requirement specified as 'Self.AssocP4' == 'Bool')}}
// expected-note@-2 {{candidate requires that the types 'S4aHelper' and 'Bool' be equivalent (requirement specified as 'Self.AssocP4' == 'Bool')}}
func extP4a() -> Bool { return reqP4a() }
}
func testP4(_ s4a: S4a, s4b: S4b, s4c: S4c, s4d: S4d) {
s4a.extP4a() // expected-error{{no exact matches in call to instance method 'extP4a'}}
s4a.extP4a() // expected-error{{referencing instance method 'extP4a()' on 'P4' requires that 'S4aHelper' conform to 'P1'}}
s4b.extP4a() // ok
s4c.extP4a() // expected-error{{no exact matches in call to instance method 'extP4a'}}
s4c.extP4a() // expected-error{{referencing instance method 'extP4a()' on 'P4' requires that 'Int' conform to 'P1'}}
s4c.extP4Int() // okay
var b1 = s4d.extP4a() // okay, "Bool" version
b1 = true // checks type above

View File

@@ -76,13 +76,14 @@ func nestedOptContext() -> Foo?? {
// This should diagnose instead of crashing in SILGen
protocol Horse {
static var palomino: Horse { get }
static var palomino: Horse { get } // expected-note {{'palomino' declared here}}
}
func rideAHorse(_ horse: Horse?) {}
rideAHorse(.palomino)
// expected-error@-1 {{static member 'palomino' cannot be used on protocol metatype 'Horse.Protocol'}}
// expected-error@-1 {{cannot reference static property 'palomino' on 'Horse.Protocol' with non-conforming result type 'Horse'}}
// expected-note@-2 {{only concrete types such as structs, enums and classes can conform to protocols}}
// FIXME: This should work if the static member is part of a class though
class Donkey {