Skip to content

Commit 4f86785

Browse files
authored
Merge pull request #58624 from CodaFi/existence-is-suffering
Existential Types Cannot Satisfy Superclass Bounds
2 parents eb8df86 + 6d28831 commit 4f86785

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,8 +3465,11 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
34653465
if (!req)
34663466
return getTypeMatchFailure(locator);
34673467

3468-
if (type1->isPlaceholder() ||
3469-
req->getRequirementKind() == RequirementKind::Superclass)
3468+
// Superclass constraints are never satisfied by existentials,
3469+
// even those that contain the superclass a la `any C & P`.
3470+
if (!type1->isExistentialType() &&
3471+
(type1->isPlaceholder() ||
3472+
req->getRequirementKind() == RequirementKind::Superclass))
34703473
return getTypeMatchSuccess();
34713474

34723475
auto *fix = fixRequirementFailure(*this, type1, type2, locator);

test/Constraints/members.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,3 +753,25 @@ func fSR14533(_ s: SR14533) {
753753
// expected-error@-1{{value of type 'SR14533' has no member 'ys'}}
754754
}
755755
}
756+
757+
// rdar://92358570
758+
class SomeClassBound {}
759+
protocol ClassBoundProtocol: SomeClassBound {
760+
}
761+
762+
struct RDAR92358570<Element> {}
763+
764+
extension RDAR92358570 where Element : SomeClassBound {
765+
// expected-note@-1 2 {{where 'Element' = 'any ClassBoundProtocol', 'SomeClassBound' = 'AnyObject'}}
766+
// expected-note@-2 2 {{where 'Element' = 'any SomeClassBound & ClassBoundProtocol', 'SomeClassBound' = 'AnyObject'}}
767+
func doSomething() {}
768+
static func doSomethingStatically() {}
769+
}
770+
771+
func rdar92358570(_ x: RDAR92358570<ClassBoundProtocol>, _ y: RDAR92358570<SomeClassBound & ClassBoundProtocol>) {
772+
x.doSomething() // expected-error {{referencing instance method 'doSomething()' on 'RDAR92358570' requires that 'any ClassBoundProtocol' inherit from 'AnyObject'}}
773+
RDAR92358570<ClassBoundProtocol>.doSomethingStatically() // expected-error {{referencing static method 'doSomethingStatically()' on 'RDAR92358570' requires that 'any ClassBoundProtocol' inherit from 'AnyObject'}}
774+
775+
y.doSomething() // expected-error {{referencing instance method 'doSomething()' on 'RDAR92358570' requires that 'any SomeClassBound & ClassBoundProtocol' inherit from 'AnyObject'}}
776+
RDAR92358570<SomeClassBound & ClassBoundProtocol>.doSomethingStatically() // expected-error {{referencing static method 'doSomethingStatically()' on 'RDAR92358570' requires that 'any SomeClassBound & ClassBoundProtocol' inherit from 'AnyObject'}}
777+
}

0 commit comments

Comments
 (0)