Skip to content

Add a test for a corner case missed by #41978. #58706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,12 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
return expr;
};

auto maybeUnwrapConversions = [](Expr *expr) {
if (auto *covariantReturn = dyn_cast<CovariantReturnConversionExpr>(expr))
expr = covariantReturn->getSubExpr();
return expr;
};

switch (getThunkKind()) {
case AutoClosureExpr::Kind::None:
case AutoClosureExpr::Kind::AsyncLet:
Expand All @@ -1916,6 +1922,7 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
body = body->getSemanticsProvidingExpr();
body = maybeUnwrapOpenExistential(body);
body = maybeUnwrapOptionalEval(body);
body = maybeUnwrapConversions(body);

if (auto *outerCall = dyn_cast<ApplyExpr>(body)) {
return outerCall->getFn();
Expand All @@ -1934,6 +1941,7 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
innerBody = innerBody->getSemanticsProvidingExpr();
innerBody = maybeUnwrapOpenExistential(innerBody);
innerBody = maybeUnwrapOptionalEval(innerBody);
innerBody = maybeUnwrapConversions(innerBody);

if (auto *outerCall = dyn_cast<ApplyExpr>(innerBody)) {
if (auto *innerCall = dyn_cast<ApplyExpr>(outerCall->getFn())) {
Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/objc_parse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func ivars(_ hive: Hive) {
hive.queen.description() // expected-error{{value of type 'Hive' has no member 'queen'}}
}

class NSObjectable : NSObjectProtocol {
class NSObjectable : NSObjectProtocol { // expected-error {{cannot declare conformance to 'NSObjectProtocol' in Swift; 'NSObjectable' should inherit 'NSObject' instead}}
@objc var description : String { return "" }
@objc(conformsToProtocol:) func conforms(to _: Protocol) -> Bool { return false }
@objc(isKindOfClass:) func isKind(of aClass: AnyClass) -> Bool { return false }
Expand Down
15 changes: 15 additions & 0 deletions test/Index/index_curry_thunk_objc.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -enable-objc-interop -print-indexed-symbols -source-filename %s | %FileCheck %s
// REQUIRES: objc_interop

import Foundation

@objc
class Foo: NSObject {
// CHECK-DAG: constructor/Swift | init(object:)
init(object: Any?) {}
}

extension Foo {
// CHECK-DAG: static-property/Swift | boom
static let boom = Foo(object: self)
}
1 change: 1 addition & 0 deletions test/Inputs/clang-importer-sdk/usr/include/objc/NSObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@class NSString;

@protocol NSObject
- (instancetype)self;
@property (readonly, copy) NSString *description;
- (instancetype)retain OBJC_ARC_UNAVAILABLE;
- (Class)class;
Expand Down
16 changes: 0 additions & 16 deletions test/PrintAsObjC/classes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,6 @@ class ClassWithCustomName2 {}
@objc(CustomNameSub)
class ClassWithCustomNameSub : ClassWithCustomName {}


// CHECK-LABEL: @interface ClassWithNSObjectProtocol <NSObject>
// CHECK-NEXT: @property (nonatomic, readonly, copy) NSString * _Nonnull description;
// CHECK-NEXT: - (BOOL)conformsToProtocol:(Protocol * _Nonnull)_ SWIFT_WARN_UNUSED_RESULT;
// CHECK-NEXT: - (BOOL)isKindOfClass:(Class _Nonnull)aClass SWIFT_WARN_UNUSED_RESULT;
// CHECK-NEXT: - (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
// CHECK-NEXT: @end
@objc @objcMembers class ClassWithNSObjectProtocol : NSObjectProtocol {
@objc var description: String { return "me" }
@objc(conformsToProtocol:)
func conforms(to _: Protocol) -> Bool { return false }

@objc(isKindOfClass:)
func isKind(of aClass: AnyClass) -> Bool { return false }
}

// CHECK-LABEL: @interface DiscardableResult : NSObject
// CHECK-NEXT: - (NSInteger)nonDiscardable:(NSInteger)x SWIFT_WARN_UNUSED_RESULT;
// CHECK-NEXT: - (NSInteger)discardable:(NSInteger)x;
Expand Down