Skip to content

[SR-11073] Generic subclass does not respond to selector if conforming Objective-C protocol #53465

@swift-ci

Description

@swift-ci
Previous ID SR-11073
Radar None
Original Reporter andoku901 (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

XCode 10.2.1 default toolchain

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 6d8b5869344f293ba1395c7797c79f52

duplicates:

Issue Description:

Write the following code in a Swift file:

class SwiftVC<View: UIView>: UIViewController, UICollectionViewDelegateFlowLayout {
    var rootView: View? {
        return self.view as? View
    }
}

final class SubSwiftVC: SwiftVC<UIView> {
    func collectionView(_ collectionView: UICollectionView,
                        layout collectionViewLayout: UICollectionViewLayout,
                        sizeForItemAt indexPath: IndexPath) -> CGSize
    {
        return .zero
    }
}

class SwiftVCAdaptor: NSObject {
    @objc func vc() -> UIViewController {
        return SubSwiftVC()
    }
}

Then write in an Objective-C file the next:

    UIViewController *vc = [[SwiftVCAdaptor new] vc];
    if ([vc respondsToSelector:@selector(collectionView:layout:sizeForItemAtIndexPath:)]) {
        // This is not executed.
    }

This behavior can be fixed by declaring collectionView:layout:sizeForItemAt: method in SwiftVC and overriding it in SubSwiftVC.

Metadata

Metadata

Assignees

No one assigned

    Labels

    @objcFeature → attributes: The @objc attributeattributesFeature: Declaration and type attributesbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesduplicateResolution: Duplicates another issueobjective-c interopFeature: Interoperability with Objective-Cregressionswift 5.0type checkerArea → compiler: Semantic analysisunexpected behaviorBug: Unexpected behavior or incorrect outputwhole module optimization onlyFlag: An issue whose reproduction requires whole module optimization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions