Skip to content

Commit 30f2557

Browse files
committed
[Diagnostics] NFC: Adjust all diagnostics improved/changed by static member refs on protocol metatypes feature
1 parent feb8684 commit 30f2557

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6881,6 +6881,13 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
68816881
if (auto *fnType = resultTy->getAs<FunctionType>())
68826882
resultTy = fnType->getResult();
68836883

6884+
// No reason to suggest that `Void` doesn't conform to some protocol.
6885+
if (resultTy->isVoid()) {
6886+
result.addUnviable(candidate,
6887+
MemberLookupResult::UR_TypeMemberOnInstance);
6888+
return;
6889+
}
6890+
68846891
// If result is not a concrete type which could conform to the
68856892
// expected protocol, this method is only viable for diagnostics.
68866893
if (!(resultTy->is<NominalType>() || resultTy->is<BoundGenericType>()) ||

test/Generics/where_clause_contextually_generic_decls.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protocol Whereable {
3232
}
3333

3434
extension Whereable {
35-
// expected-note@+1 {{where 'Self' = 'T1'}}
35+
// expected-note@+1 {{'staticExtensionFunc(arg:)' declared here}}
3636
static func staticExtensionFunc(arg: Self.Element) -> Self.Element
3737
where Self: Sequence {
3838
return arg
@@ -53,7 +53,7 @@ func testProtocolExtensions<T1, T2, T3, T4>(t1: T1, t2: T2, t3: T3, t4: T4)
5353
T2: Whereable & Sequence,
5454
T3: Whereable, T3.Assoc == T3.Bssoc,
5555
T4: Whereable, T4.Assoc: Whereable {
56-
_ = T1.staticExtensionFunc // expected-error {{static method 'staticExtensionFunc(arg:)' requires that 'T1' conform to 'Sequence'}}
56+
_ = T1.staticExtensionFunc // expected-error {{cannot reference static method 'staticExtensionFunc(arg:)' on 'Whereable.Protocol' with non-conforming result type '_.Element'}}
5757
_ = T2.staticExtensionFunc
5858

5959
t1.extensionFunc() // expected-error {{instance method 'extensionFunc()' requires the types 'T1.Assoc' and 'T1.Bssoc' be equivalent}}

test/decl/ext/protocol.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ extension AnotherBazProtocol where BazValue: AnotherBazProtocol {} // ok, does n
197197
// Protocol extensions with additional requirements
198198
// ----------------------------------------------------------------------------
199199
extension P4 where Self.AssocP4 : P1 {
200-
// expected-note@-1 {{candidate requires that 'Int' conform to 'P1' (requirement specified as 'Self.AssocP4' == 'P1')}}
201-
// expected-note@-2 {{candidate requires that 'S4aHelper' conform to 'P1' (requirement specified as 'Self.AssocP4' == 'P1')}}
200+
// expected-note@-1 {{where 'Self.AssocP4' = 'Int'}}
201+
// expected-note@-2 {{where 'Self.AssocP4' = 'S4aHelper'}}
202202
func extP4a() {
203203
acceptsP1(reqP4a())
204204
}
@@ -230,15 +230,13 @@ extension P4 where Self.AssocP4 == Int { // expected-note {{where 'Self.AssocP4'
230230
}
231231

232232
extension P4 where Self.AssocP4 == Bool {
233-
// expected-note@-1 {{candidate requires that the types 'Int' and 'Bool' be equivalent (requirement specified as 'Self.AssocP4' == 'Bool')}}
234-
// expected-note@-2 {{candidate requires that the types 'S4aHelper' and 'Bool' be equivalent (requirement specified as 'Self.AssocP4' == 'Bool')}}
235233
func extP4a() -> Bool { return reqP4a() }
236234
}
237235

238236
func testP4(_ s4a: S4a, s4b: S4b, s4c: S4c, s4d: S4d) {
239-
s4a.extP4a() // expected-error{{no exact matches in call to instance method 'extP4a'}}
237+
s4a.extP4a() // expected-error{{referencing instance method 'extP4a()' on 'P4' requires that 'S4aHelper' conform to 'P1'}}
240238
s4b.extP4a() // ok
241-
s4c.extP4a() // expected-error{{no exact matches in call to instance method 'extP4a'}}
239+
s4c.extP4a() // expected-error{{referencing instance method 'extP4a()' on 'P4' requires that 'Int' conform to 'P1'}}
242240
s4c.extP4Int() // okay
243241
var b1 = s4d.extP4a() // okay, "Bool" version
244242
b1 = true // checks type above

test/expr/postfix/dot/optional_context_member.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@ func nestedOptContext() -> Foo?? {
7676

7777
// This should diagnose instead of crashing in SILGen
7878
protocol Horse {
79-
static var palomino: Horse { get }
79+
static var palomino: Horse { get } // expected-note {{'palomino' declared here}}
8080
}
8181

8282
func rideAHorse(_ horse: Horse?) {}
8383

8484
rideAHorse(.palomino)
85-
// expected-error@-1 {{static member 'palomino' cannot be used on protocol metatype 'Horse.Protocol'}}
85+
// expected-error@-1 {{cannot reference static property 'palomino' on 'Horse.Protocol' with non-conforming result type 'Horse'}}
86+
// expected-note@-2 {{only concrete types such as structs, enums and classes can conform to protocols}}
8687

8788
// FIXME: This should work if the static member is part of a class though
8889
class Donkey {

0 commit comments

Comments
 (0)