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-1430] Swift 3 no longer automatically coerces Double literal argument to CGFloat #44039

Closed
mattneub opened this issue May 6, 2016 · 9 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself SDKOverlay standard library Area: Standard library umbrella

Comments

@mattneub
Copy link

mattneub commented May 6, 2016

Previous ID SR-1430
Radar rdar://problem/26148507
Original Reporter @mattneub
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 7.3.1 Toolchain: Swift Development Snapshot 2016-05-03 (a)

Additional Detail from JIRA
Votes 0
Component/s Compiler, Standard Library
Labels Bug, SDKOverlay
Assignee @rjmccall
Priority Medium

md5: 66ca49b2b3122af47873b7d0d5624894

is duplicated by:

  • SR-1479 UIColor Float-based initializer shouldn't be there

Issue Description:

This code, which has compiled since the dawn of Swift, no longer compiles in Swift 3:

let col = UIColor(red: 0.5, green: 0.6, blue: 0.7, alpha: 1.0)

The error message is: "Ambiguous use of init(red:green:blue:alpha:)". But there is no such ambiguity.

I can work around the problem by explicitly coercing all those Double literals to CGFloat, but I shouldn't have to.

@belkadan
Copy link
Contributor

belkadan commented May 6, 2016

I can't reproduce this in simple tests—not quite the situation you're setting up, but just xcrun -sdk iphonesimulator /path/to/built/swiftc -parse with a very recent built-by-hand Swift. Is there anything else in your project?

@mattneub
Copy link
Author

mattneub commented May 6, 2016

@belkadan I can reproduce reliably in an actual iOS project. I've uploaded one. It's basically a one-liner:

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        _ = UIColor(red:0.5, green:0.6, blue:0.7, alpha:1.0) // error
    }

}

This is Xcode in El Capitan with the 05-03 toolchain, so if you don't see the same thing, maybe it's been fixed in the daily build?

@belkadan
Copy link
Contributor

belkadan commented May 6, 2016

I'm still not seeing this. Xcode 7.3.1 (7D1014), with iOS SDK 13E238 (xcodebuild -version -sdk iphoneos), and the 2016-05-03 toolchain from swift.org.

…aha, wait, it compiles cleanly, but Live Issues is showing an error. And now I see we have an overload that takes Float parameters, which comes from the implementation of ColorLiteralConvertible, which no longer has argument labels that distinguish it from a non-literal initializer. @tkremenek, what do you want to do about this?

@belkadan
Copy link
Contributor

belkadan commented May 6, 2016

The "compiles cleanly" part is a bit strange too. Might be compiler non-determinism.

@mattneub
Copy link
Author

mattneub commented May 8, 2016

Interestingly, I can work around this by casting just the first argument, i.e. UIColor(red: 0.5 as CGFloat, green: 0.6, blue: 0.7, alpha: 1.0)

@lattner
Copy link
Mannequin

lattner mannequin commented May 11, 2016

I believe that this is a known bug (that we really need to fix) where the initializer for the playground literal for colors is ambiguous with the normal init. We should rename the init method in the playground literal protocol.

@lattner
Copy link
Mannequin

lattner mannequin commented May 13, 2016

@rjmccall did you just fix this?

@rjmccall
Copy link
Member

Yes, this is fixed now.

@mattneub
Copy link
Author

mattneub commented Jun 2, 2016

Thanks, now that the May 31 toolchain is out I can confirm this is fixed.

@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 SDKOverlay standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants