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-5137] Corrupt Return Value from Method Returning Tuple #47713

Closed
troughton opened this issue Jun 7, 2017 · 7 comments
Closed

[SR-5137] Corrupt Return Value from Method Returning Tuple #47713

troughton opened this issue Jun 7, 2017 · 7 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.0

Comments

@troughton
Copy link
Contributor

Previous ID SR-5137
Radar rdar://problem/32618125
Original Reporter @troughton
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Swift 4.0/Swift 3.2, Xcode 9 beta

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.0Regression, Miscompile
Assignee @aschwaighofer
Priority Medium

md5: 1da37c68a65328553195e7c579800594

Issue Description:

In Swift 4/Swift 3.2 mode, return values of a function that returns a tuple are corrupted.

Within the method, variables have the correct value, but outside of it they have an incorrect value returned. I've attached an example project that exhibits this issue.

This code compiled correctly in Swift 3 (Xcode 8.3.2).

e.g.

extension Matrix4x4f {
    public var decomposed : (translation: Vector3f, rotation: Quaternion, scale: Vector3f) {
        let translation = ...
        let scale = ...
        let rotation = ...
        
        print("Value within method: \(translation), \(rotation), \(scale)")
        return (translation, rotation, scale)
    }
}

let matrix = Matrix4x4f.lookAt(eye: Vector3f(1, 1, 1), at: Vector3f(0, 0, 0))

let (translation, rotation, scale) = matrix.decomposed
print("Value returned: \(translation), \(rotation), \(scale)")

outputs:

Value within method: Vector3f(x: -0.0, y: -0.0, z: 1.73205), Quaternion(x: -0.115917, y: 0.880476, z: -0.279848, w: 0.364705), Vector3f(x: 1.0, y: 1.0, z: 1.0)
Value returned: Vector3f(x: -0.0, y: -0.0, z: 1.73205), Quaternion(x: 0.0, y: 0.0, z: -0.279848, w: 0.364705), Vector3f(x: 1.0, y: 1.0, z: 0.0)

@belkadan
Copy link
Contributor

belkadan commented Jun 7, 2017

@swift-ci create

@troughton
Copy link
Contributor Author

I may have accidentally uploaded a non-working project before; apologies if you tried to run it. I've fixed the issues in the project in swift4bug.zip and you should now be able to run it without problems.

@bob-wilson
Copy link

I was just about to ask about that. The revised project builds with Xcode 8.3.2 but the output just shows "Opaque Value":

Value within method: Vector3f(d: simd.float3(_vector: (Opaque Value))), Quaternion(x: Swift.Float(_value: (Opaque Value)), y: Swift.Float(_value: (Opaque Value)), z: Swift.Float(_value: (Opaque Value)), w: Swift.Float(_value: (Opaque Value))), Vector3f(d: simd.float3(_vector: (Opaque Value)))
Value returned: Vector3f(d: simd.float3(_vector: (Opaque Value))), Quaternion(x: Swift.Float(_value: (Opaque Value)), y: Swift.Float(_value: (Opaque Value)), z: Swift.Float(_value: (Opaque Value)), w: Swift.Float(_value: (Opaque Value))), Vector3f(d: simd.float3(_vector: (Opaque Value)))

@troughton
Copy link
Contributor Author

That's doubly odd. I downloaded the project again and I'm getting the same results – but Vector3.swift declares a conformance to CustomStringConvertible, and so my understanding is that that should be called when 'print'ing the value – maybe that's a second bug? Calling .description on the objects seems to work – I'll upload another project that does that soon.

That output was also from running that original test case code, so perhaps Xcode was using an old module cache or something like that, and as such I was getting the correct output? I'm not entirely sure – just worth pointing out that I did get the output above by running the first project I submitted.

@troughton
Copy link
Contributor Author

See 'Swift 4 Bug - Amended.zip' for a version that I've just tested across two different computers after running a clean build and that displays the issue on Xcode 9 beta for me. If that also has issues then I'll be very perplexed.

@bob-wilson
Copy link

OK, I can reproduce it with that latest version.

@aschwaighofer
Copy link
Member

Fixed: #10501

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

No branches or pull requests

5 participants