Skip to content

Commit 82d2d3e

Browse files
committed
Sema: Tweak inheritance clause checks for primitive AnyObject
1 parent e91ab9f commit 82d2d3e

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,19 @@ void TypeChecker::checkInheritanceClause(Decl *decl,
444444
// protocols.
445445
if (inheritedTy->isExistentialType()) {
446446
auto layout = inheritedTy->getExistentialLayout();
447-
for (auto proto : layout.getProtocols()) {
448-
auto *protoDecl = proto->getDecl();
449-
allProtocols.insert(protoDecl);
447+
448+
// Classes and extensions cannot inherit from subclass
449+
// existentials or AnyObject.
450+
if (isa<ProtocolDecl>(decl) ||
451+
isa<AbstractTypeParamDecl>(decl) ||
452+
(!layout.hasExplicitAnyObject &&
453+
!layout.superclass)) {
454+
for (auto proto : layout.getProtocols()) {
455+
auto *protoDecl = proto->getDecl();
456+
allProtocols.insert(protoDecl);
457+
}
458+
continue;
450459
}
451-
continue;
452460
}
453461

454462
// If this is an enum inheritance clause, check for a raw type.

test/type/subclass_composition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ class ClassConformsToClassProtocolBad2 : ProtoRefinesClass {} // FIXME
463463
class ClassConformsToClassProtocolGood2 : Derived, ProtoRefinesClass {}
464464

465465
// Subclass existentials inside inheritance clauses
466-
class CompositionInClassInheritanceClauseAlias : BaseIntAndP2 {
466+
class CompositionInClassInheritanceClauseAlias : BaseIntAndP2 { // FIXME: expected-error {{}}
467467
required init(classInit: ()) {
468468
super.init(classInit: ()) // FIXME: expected-error {{}}
469469
}

0 commit comments

Comments
 (0)