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-1216] Struct initializers defined in an extension are miscompiled with optimizations on. #43824

Closed
swift-ci opened this issue Apr 12, 2016 · 5 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1216
Radar rdar://problem/25779542
Original Reporter nerdyc (JIRA User)
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

Swift 2.2, Xcode 7.3

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, OptimizedOnly
Assignee @swiftix
Priority Medium

md5: f2565072210dec5839e405dd901df431

relates to:

  • SR-1217 Wrong value after optimizations on Xcode 7.3 / Swift 2.2

Issue Description:

Given the following struct:

struct SimpleRecord {
    
    let id:Int64
    let name:String
    
    init(name:String) {
        self.id = 1
        self.name = name
    }
    
}

extension SimpleRecord {
    
    init(recordId:Int64) {
        self.id = recordId
        self.name = "Record #\(recordId)"
    }
    
    var recordId:Int64 {
        // BUG: This always returns '1'
        return id
    }
    
}

The "recordId" property will always return 1, even when the "id" property returns something different. For example:

let record = SimpleRecord(recordId:123)
record.id // 123
record.recordId // 1

This only happens if the initializer is defined in an extension. Placing all the code in the struct works fine.

This seems similar to #SR-1026, but is different since I can see both values. The struct seems to be initialized correctly, but the extension method seems to be optimized out.

Unlike SR-1026, whole-module optimization is not enabled. Just the standard optimization.

I've attached a sample Mac App that highlights the behavior.

@rudkx
Copy link
Member

rudkx commented Apr 20, 2016

I suspect this is actually the same issue as SR-1217.

Roman, what do you think?

@swiftix
Copy link
Mannequin

swiftix mannequin commented Apr 20, 2016

Could you try to build your project with the Xcode 7.3.1 GM? We fixed a couple of bugs related to your bug report in this release.
Please let us know if the bug is still there.

@swift-ci
Copy link
Collaborator Author

Comment by Christian Niles (JIRA)

Downloading it now. I'll update this afternoon (PST) after I've finished installing.

@swift-ci
Copy link
Collaborator Author

Comment by Christian Niles (JIRA)

Confirmed: This is fixed in Xcode 7.3.1.

Thanks!

@swiftix
Copy link
Mannequin

swiftix mannequin commented Apr 21, 2016

Was fixed in Xcode 7.3.1

@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 optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

No branches or pull requests

2 participants