-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.conformancesFeature → protocol: protocol conformancesFeature → protocol: protocol conformancesobjective-c interopFeature: Interoperability with Objective-CFeature: Interoperability with Objective-Crun-time crashBug → crash: Swift code crashed during executionBug → crash: Swift code crashed during execution
Description
Description
For protocols defined in ObjC, its API names need some transformation to conform to Swift naming conventions.
When using a class extension to conform to such a protocol, if API name incorrectly uses ObjC convention, compiler will catch it saying "XXX has been renamed to YYY".
However, if I declare the conformance using one extension but putt its API implementation in another extension, the incorrect API name won't be caught and a runtime crash will happen when the delegate API is called.
Reproduction
@protocol ListAdapterDelegate <NSObject>
- (void)listAdapter:(id)listAdapter
willDisplayObject:(id)object
atIndexPath:(NSIndexPath *)indexPath;
@end
@protocol ListDisplayDelegate <NSObject>
- (void)listAdapter:(id)listAdapter willDisplaySectionController:(id)sectionController;
@endclass Foo {}
extension Foo: ListDisplayDelegate {
func listAdapter(_ listAdapter: Any, willDisplaySectionController sectionController: Any) {
}
// Wrong name but compiles
func listAdapter(_ listAdapter: Any, willDisplayObject object: Any, atIndexPath indexPath: IndexPath) {
}
}
extension Foo: ListAdapterDelegate {
// Correct one should be
// func listAdapter(_ listAdapter: Any, willDisplay object: Any, at indexPath: IndexPath) {
//
// }
}Stack dump
objc_exception_throw (Unknown Source:0)
-[NSObject(NSObject) doesNotRecognizeSelector:] (Unknown Source:0)
Expected behavior
Compiler catches the issue
Environment
swift-driver version: 1.127.14.1 Apple Swift version 6.2 (swiftlang-6.2.0.19.9 clang-1700.3.19.1)
Additional information
No response
NSProgrammer and barabashd
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.conformancesFeature → protocol: protocol conformancesFeature → protocol: protocol conformancesobjective-c interopFeature: Interoperability with Objective-CFeature: Interoperability with Objective-Crun-time crashBug → crash: Swift code crashed during executionBug → crash: Swift code crashed during execution