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-9541] Swift incorrectly fills in ivar attribute for static properties in categories #51991

Closed
swift-ci opened this issue Dec 19, 2018 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself IRGen LLVM IR generation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-9541
Radar rdar://problem/46830117
Original Reporter fclout (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment

Tested on Swift 4.2, will try on a nightly shortly.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, IRGen
Assignee fclout (JIRA)
Priority Medium

md5: a58e6adb86c07765d89d9b61a502e5d3

Issue Description:

Objective-C does not support ivars on classes, and does not support adding ivars in categories. You can then imagine my surprise when I found programs that claim that they have class properties, defined in categories, that are backed by ivars.

The Swift compiler appears to co-opt the ivar field to put the name of the variable that holds the value of a static property, even though that variable is not an ivar.

Build this:

import Foundation

@objc public extension Formatter {
    @objc static var iso8601: Int = 0
}

then inspect it with your favorite disassembler. You can see that the NSFormatter (test) category defines an "iso8601" class property with the type string "Tq,N,Viso8601" (data type signed long long, nonatomic, backed by ivar called iso8601).

@belkadan
Copy link
Contributor

Whoops! This probably fell out of adding support for ObjC class properties.

@swift-ci
Copy link
Collaborator Author

Comment by Félix Cloutier (JIRA)

Created a PR (which is not yet ready to merge): #21435

@swift-ci
Copy link
Collaborator Author

Comment by Félix Cloutier (JIRA)

Fixed in #21435.

@belkadan
Copy link
Contributor

5.0: #21481

@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 IRGen LLVM IR generation
Projects
None yet
Development

No branches or pull requests

2 participants