Skip to content

Commit 9203d45

Browse files
committed
Add a test for a corner case missed by #41978.
A member reference to a function with a dynamic 'Self' result type can introduce a covariant return expression into the AST. This is exposed by the (already deeply cursed) -self method on NSObject(Protocol). Add a regression test and said cursed member to the mock SDK.
1 parent b73b77d commit 9203d45

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/AST/Expr.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,12 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
19061906
return expr;
19071907
};
19081908

1909+
auto maybeUnwrapConversions = [](Expr *expr) {
1910+
if (auto *covariantReturn = dyn_cast<CovariantReturnConversionExpr>(expr))
1911+
expr = covariantReturn->getSubExpr();
1912+
return expr;
1913+
};
1914+
19091915
switch (getThunkKind()) {
19101916
case AutoClosureExpr::Kind::None:
19111917
case AutoClosureExpr::Kind::AsyncLet:
@@ -1916,6 +1922,7 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
19161922
body = body->getSemanticsProvidingExpr();
19171923
body = maybeUnwrapOpenExistential(body);
19181924
body = maybeUnwrapOptionalEval(body);
1925+
body = maybeUnwrapConversions(body);
19191926

19201927
if (auto *outerCall = dyn_cast<ApplyExpr>(body)) {
19211928
return outerCall->getFn();
@@ -1934,6 +1941,7 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
19341941
innerBody = innerBody->getSemanticsProvidingExpr();
19351942
innerBody = maybeUnwrapOpenExistential(innerBody);
19361943
innerBody = maybeUnwrapOptionalEval(innerBody);
1944+
innerBody = maybeUnwrapConversions(innerBody);
19371945

19381946
if (auto *outerCall = dyn_cast<ApplyExpr>(innerBody)) {
19391947
if (auto *innerCall = dyn_cast<ApplyExpr>(outerCall->getFn())) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -enable-objc-interop -print-indexed-symbols -source-filename %s | %FileCheck %s
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
6+
@objc
7+
class Foo: NSObject {
8+
// CHECK-DAG: constructor/Swift | init(object:)
9+
init(object: Any?) {}
10+
}
11+
12+
extension Foo {
13+
// CHECK-DAG: static-property/Swift | boom
14+
static let boom = Foo(object: self)
15+
}

test/Inputs/clang-importer-sdk/usr/include/objc/NSObject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@class NSString;
77

88
@protocol NSObject
9+
- (instancetype)self;
910
@property (readonly, copy) NSString *description;
1011
- (instancetype)retain OBJC_ARC_UNAVAILABLE;
1112
- (Class)class;

0 commit comments

Comments
 (0)