Skip to content

Commit 4ef5147

Browse files
authored
Merge pull request #4735 from jrose-apple/swift-3-AnyObject-to-Any-fix-it
Provide a fix-it when overriding 'Any' with 'AnyObject'.
2 parents 0732a89 + 8f11cae commit 4ef5147

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,16 +1142,23 @@ bool swift::fixItOverrideDeclarationTypes(TypeChecker &TC,
11421142
return ty;
11431143
};
11441144

1145-
// Is the base type bridged?
11461145
Type normalizedBaseTy = normalizeType(baseTy);
11471146
const DeclContext *DC = decl->getDeclContext();
1148-
Optional<Type> maybeBridged =
1149-
TC.Context.getBridgedToObjC(DC, normalizedBaseTy, &TC);
11501147

1148+
// Is the base type bridged?
11511149
// ...and just knowing that it's bridged isn't good enough if we don't
11521150
// know what it's bridged /to/. Also, don't do this check for trivial
11531151
// bridging---that doesn't count.
1154-
Type bridged = maybeBridged.getValueOr(Type());
1152+
Type bridged;
1153+
if (normalizedBaseTy->isAny()) {
1154+
const ProtocolDecl *anyObjectProto =
1155+
TC.Context.getProtocol(KnownProtocolKind::AnyObject);
1156+
bridged = anyObjectProto->getDeclaredType();
1157+
} else {
1158+
Optional<Type> maybeBridged =
1159+
TC.Context.getBridgedToObjC(DC, normalizedBaseTy, &TC);
1160+
bridged = maybeBridged.getValueOr(Type());
1161+
}
11551162
if (!bridged || bridged->isEqual(normalizedBaseTy))
11561163
return false;
11571164

test/ClangModules/objc_bridging_custom.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Base : NSObject {
2323
class func testInout(_: inout Refrigerator) {} // expected-note {{potential overridden class method 'testInout' here}}
2424
func testUnmigrated(a: NSRuncingMode, b: Refrigerator, c: NSCoding) {} // expected-note {{potential overridden instance method 'testUnmigrated(a:b:c:)' here}}
2525
func testPartialMigrated(a: NSRuncingMode, b: Refrigerator) {} // expected-note {{potential overridden instance method 'testPartialMigrated(a:b:)' here}}
26+
func testAny(a: Any, b: Any) -> Any? {} // expected-note {{potential overridden instance method 'testAny(a:b:)' here}}
2627

2728
subscript(a a: Refrigerator, b b: Refrigerator) -> Refrigerator? { // expected-note {{potential overridden subscript 'subscript(a:b:)' here}} {{none}}
2829
return nil
@@ -58,6 +59,9 @@ class Sub : Base {
5859
// expected-note@+1 {{type does not match superclass instance method with type '(NSRuncingMode, Refrigerator) -> ()'}} {{53-68=Refrigerator}}
5960
override func testPartialMigrated(a: NSObject, b: APPRefrigerator) {} // expected-error {{method does not override any method from its superclass}} {{none}}
6061

62+
// expected-note@+1 {{type does not match superclass instance method with type '(Any, Any) -> Any?'}} {{28-37=Any}} {{42-52=Any?}} {{57-66=Any}}
63+
override func testAny(a: AnyObject, b: AnyObject?) -> AnyObject {} // expected-error {{method does not override any method from its superclass}}
64+
6165
// expected-note@+1 {{type does not match superclass subscript with type '(Refrigerator, Refrigerator) -> Refrigerator?'}} {{27-42=Refrigerator}} {{49-65=Refrigerator?}} {{70-85=Refrigerator}}
6266
override subscript(a a: APPRefrigerator, b b: APPRefrigerator?) -> APPRefrigerator { // expected-error {{subscript does not override any subscript from its superclass}} {{none}}
6367
return a

0 commit comments

Comments
 (0)