Skip to content

Commit 5aa05b2

Browse files
authored
Merge pull request #58640 from CodaFi/sui-generics
[5.7] Existential Types Cannot Satisfy Superclass Bounds
2 parents 40a930e + 749e192 commit 5aa05b2

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
@@ -3467,8 +3467,11 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
34673467
if (!req)
34683468
return getTypeMatchFailure(locator);
34693469

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

34743477
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)