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-2139] 'let' ivars in generic subclass of NSObject invalid #44747

Closed
swift-ci opened this issue Jul 21, 2016 · 4 comments
Closed

[SR-2139] 'let' ivars in generic subclass of NSObject invalid #44747

swift-ci opened this issue Jul 21, 2016 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 3.0

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-2139
Radar rdar://problem/27495735
Original Reporter mattgallagher (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Version 8.0 beta 3 (8S174q)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.0Regression
Assignee None
Priority Medium

md5: 4bbf8b4677cba6abe7fe12f3e7f55197

Issue Description:

The following code should print "5" but prints "0" in Swift 3 (both -O and -Onone)

Code works as expected in Swift 2.3.

import Foundation

class Box<T>: NSObject {
    let value: T
    init(_ t: T) {
        value = t
    }
}

let b = Box(5)
print(b.value)

Any of the following will work around the problem: don't inherit from NSObject, replace generic parameter with `Int`, replace `let` with `var`.

According to debugger, correct value is passed into constructor and assigned to `value`. Problem appears to occur after that point.

@belkadan
Copy link
Contributor

Yikes. @jckarter, @slavapestov, any ideas?

@swift-ci
Copy link
Collaborator Author

Comment by Matt Gallagher (JIRA)

In the latest beta (Xcode beta 5) this problem does not always occur. Roughly 30% of the time, going around in a: clean project -> build -> run, the result is 0 and 70% of the time it's 5. Something dirty happening.

@belkadan
Copy link
Contributor

belkadan commented Aug 1, 2017

Whatever this was, we seem to have fixed it. I suspect it was Slava's work fixing instance variable offsets for generic subclasses of Objective-C classes.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Aug 2, 2017

Comment by Matt Gallagher (JIRA)

Just adding confirmation that this appears to be fixed. Sorry I didn't revisit this myself... it appears to be fixed since Xcode 8.3.

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

No branches or pull requests

3 participants