Skip to content

Commit 6d9e921

Browse files
committed
Restrict the ability to specify "protocol P : class, AnyObject" to Swift >= 5.
1 parent d0aa22c commit 6d9e921

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,9 @@ void TypeChecker::checkInheritanceClause(Decl *decl,
477477
if (knownType != inheritedTypes.end()) {
478478
// If the duplicated type is 'AnyObject', check whether the first was
479479
// written as 'class'. Downgrade the error to a warning in such cases
480-
// for backward compatibility.
481-
if (inheritedTy->isAnyObject() &&
480+
// for backward compatibility with Swift <= 4.
481+
if (!Context.LangOpts.isSwiftVersionAtLeast(5) &&
482+
inheritedTy->isAnyObject() &&
482483
(isa<ProtocolDecl>(decl) || isa<AbstractTypeParamDecl>(decl)) &&
483484
Lexer::getTokenAtLocation(Context.SourceMgr,
484485
knownType->second.second.Start)

test/Compatibility/anyobject_class.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-typecheck-verify-swift -swift-version 3
22
// RUN: %target-typecheck-verify-swift -swift-version 4
3+
// RUN: not %target-swift-frontend -tyepcheck -swift-version 5
34

45
protocol P : class, AnyObject { } // expected-warning{{redundant inheritance from 'AnyObject' and Swift 3 'class' keyword}}{{14-21=}}
56
// expected-warning@-1{{redundant layout constraint 'Self' : 'AnyObject'}}

0 commit comments

Comments
 (0)