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-12733] The swizzled in method of a final class resolves static references to its type incorrectly since Xcode 11.4 #55178

Open
abdulowork opened this issue May 5, 2020 · 1 comment · May be fixed by #63539
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@abdulowork
Copy link
Contributor

Previous ID SR-12733
Radar rdar://problem/62895101
Original Reporter @Biboran
Type Bug
Environment

Reproducable in Playground, with any platform selected

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

md5: 5343d71f949baac6d34987d9b6effea5

Issue Description:

Since Xcode 11.4 static references to the type within a swizzled in method of a final class will resolve to the class whose method is being replaced. The issue can be reproduced in a Playground with the following code:

import Foundation

class A: NSObject {
    @objc dynamic func foo() {
    }
}

final class B: NSObject {
    @objc func swizzled_foo() {
        print("Swizzled foo in \(B.self)")
    }
}

method_exchangeImplementations(
    class_getInstanceMethod(A.self, #selector(A.foo))!,
    class_getInstanceMethod(B.self, #selector(B.swizzled_foo))!
)

A().foo()

In Xcode 11.3 the output is the expected:

Swizzled foo in B

but since Xcode 11.4 the output is:

Swizzled foo in A

Removing the final modifier from the B declaration resolves the issue.

@beccadax
Copy link
Contributor

beccadax commented May 5, 2020

@swift-ci create

@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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants