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-7971] Swift 4.2 beta | @objc protocol conformance check can incorrectly fail #50506

Closed
kwridan opened this issue Jun 11, 2018 · 3 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.2

Comments

@kwridan
Copy link

kwridan commented Jun 11, 2018

Previous ID SR-7971
Radar rdar://problem/41047313
Original Reporter @kwridan
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.2Regression
Assignee None
Priority Medium

md5: 9a12a9cce4ad3b1943e9e9d3a9f31fc3

duplicates:

  • SR-7882 Runtime crash "class does not implement methodSignatureForSelector:" in swift class

Issue Description:

Overview

In the Swift 4.2 version shipped with Xcode 10 beta 1, checking @objc protocol conformance doesn't work in certain circumstances:

  • The protocol conformance is declared in an extension

  • The conforming class contains any of the following types

    • Date

    • Data

    • URL

Details

Here's an example with a test case, given the following protocols and classes:

@objc protocol MyProtocol {
    
}

class MyClass {
    
}

extension MyClass: MyProtocol {
    
}

class MyClassWithDate {
    var date = Date()
}

extension MyClassWithDate: MyProtocol {
    
}

class MyClassWithDateAndDirectConformance: MyProtocol {
    var date = Date()
}

The following test results are obtained:

    func testMyClass() {
        let myClass = MyClass()
        let anyObject: AnyObject = myClass
        XCTAssertTrue(anyObject is MyProtocol) // Passes
        XCTAssertNotNil(anyObject as? MyProtocol) // Passes
    }
    
    func testMyClassWithDate() {
        let myClassWithDate = MyClassWithDate()
        let anyObject: AnyObject = myClassWithDate
        XCTAssertTrue(anyObject is MyProtocol) // Fails
        XCTAssertNotNil(anyObject as? MyProtocol) // Fails
    }
    
    func testMyClassWithDateAndDirectConformance() {
        let myClassWithDateAndDirectConformance = MyClassWithDateAndDirectConformance()
        let anyObject: AnyObject = myClassWithDateAndDirectConformance
        XCTAssertTrue(anyObject is MyProtocol) // Passes
        XCTAssertNotNil(anyObject as? MyProtocol) // Passes
    }
@kwridan
Copy link
Author

kwridan commented Jun 11, 2018

Oddly, in a Playground this isn't reproducible. Just occurring within Xcode projects (Frameworks / Application targets etc...)

@belkadan
Copy link
Contributor

@slavapestov, @rjmccall, how does this figure into our whole story that we figured out for classes containing resilient types?

@belkadan
Copy link
Contributor

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 regression swift 4.2
Projects
None yet
Development

No branches or pull requests

3 participants