Skip to content

Commit 4cd167c

Browse files
authored
Merge pull request #71393 from xedin/filter-out-escapable-from-leading-dot-in-generic-context
[CSBindings] Don't allow leading-dot base inference from Escapable pr…
2 parents 2092240 + a613015 commit 4cd167c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,14 +625,15 @@ bool BindingSet::finalize(
625625
for (auto *constraint : *TransitiveProtocols) {
626626
Type protocolTy = constraint->getSecondType();
627627

628-
// The Copyable protocol can't have members, yet will be a
628+
// The Copyable/Escapable protocols can't have members, yet will be a
629629
// constraint of basically all type variables, so don't suggest it.
630630
//
631631
// NOTE: worth considering for all marker protocols, but keep in
632632
// mind that you're allowed to extend them with members!
633633
if (auto p = protocolTy->getAs<ProtocolType>()) {
634634
if (ProtocolDecl *decl = p->getDecl())
635-
if (decl->isSpecificProtocol(KnownProtocolKind::Copyable))
635+
if (decl->isSpecificProtocol(KnownProtocolKind::Copyable) ||
636+
decl->isSpecificProtocol(KnownProtocolKind::Escapable))
636637
continue;
637638
}
638639

test/Constraints/static_members_on_protocol_in_generic_context.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,22 @@ func test_leading_dot_syntax_with_typelias() {
349349
test(.box) // expected-error {{type 'Box<T>.Type' cannot conform to 'Container'}} expected-note {{only concrete types such as structs, enums and classes can conform to protocols}}
350350
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
351351
}
352+
353+
extension Copyable where Self == Int {
354+
static func answer() -> Int { 42 }
355+
}
356+
357+
extension Escapable where Self == String {
358+
static func question() -> String { "" }
359+
}
360+
361+
do {
362+
func testCopyable<T: Copyable>(_: T) {}
363+
func testEscapable<T: Escapable>(_: T) {}
364+
365+
testCopyable(.answer())
366+
// expected-error@-1 {{cannot infer contextual base in reference to member 'answer'}}
367+
368+
testEscapable(.question())
369+
// expected-error@-1 {{cannot infer contextual base in reference to member 'question'}}
370+
}

0 commit comments

Comments
 (0)