Skip to content
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

[SR-9556] Swift Class Conforming to ObjC Protocol Mixes Up Methods That Take a Block and Throw #52004

Open
belkadan opened this issue Dec 20, 2018 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself PrintAsClang Area → compiler: The PrintAsClang library

Comments

@belkadan
Copy link
Contributor

Previous ID SR-9556
Radar rdar://problem/45175430
Original Reporter @belkadan
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, ClangImporter, Miscompile, PrintAsObjC
Assignee None
Priority Medium

md5: be31b506c5609f3b4bd9f08507f8c863

Issue Description:

When a Swift class conforms to an Objective-C protocol that has a method that is both passed a block and “throws” (BOOL and NSError out pointer), the types on that method’s parameter list go out of order. For instance, the method:

- (BOOL) testBlock: (BOOL (^)(void))block error: (NSError**)error;

is turned into (from the Swift generated header):

- (BOOL)testBlock:(NSError * _Nullable * _Nullable)error error:(BOOL (^ _Nonnull)(void))block;

Results:
When importing Swift generated headers into Obj-C, calling the method on a variable of the class type will result in a compiler error. Calling the method on a variable of the protocol type will crash at runtime.

// BlockTestProtocol.h
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@protocol BlockTestProtocol <NSObject>

- (BOOL) testBlock: (NS_NOESCAPE BOOL (^)(void))block error: (NSError**)error;

@end

NS_ASSUME_NONNULL_END
import Foundation

class SwiftDelegate: NSObject, BlockTestProtocol {

    func test(_ block: () -> Bool) throws {
        print(block())
    }

}
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself PrintAsClang Area → compiler: The PrintAsClang library
Projects
None yet
Development

No branches or pull requests

1 participant