Skip to content

Commit a3325bb

Browse files
committed
Sema: 'Any' can bridge to a class, so throws -> Any is allowed.
1 parent 5cef9ea commit a3325bb

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,6 +2744,10 @@ static bool isBridgedToObjectiveCClass(DeclContext *dc, Type type) {
27442744
// Simple case: bridgeable object types.
27452745
if (type->isBridgeableObjectType())
27462746
return true;
2747+
2748+
// Any bridges to AnyObject.
2749+
if (type->isAny())
2750+
return true;
27472751

27482752
// Determine whether this type is bridged to Objective-C.
27492753
ASTContext &ctx = type->getASTContext();

test/attr/attr_objc_any.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ class Foo: NSObject {
1313
@objc func method(x: Any) -> Any { return x }
1414

1515
@objc func indirectAny(x: UnsafePointer<Any>) {} // expected-error{{type of the parameter cannot be represented in Objective-C}}
16+
17+
@objc func throwingMethod(x: Any) throws -> Any { return x }
18+
19+
@objc func throwingMethod(x: Any) throws -> Any? { return x } // expected-error{{throwing method cannot be marked @objc because it returns a value of optional type 'Any?'; 'nil' indicates failure to Objective-C}}
1620
}

0 commit comments

Comments
 (0)