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-15221] Whole number literal type inference fail, maybe due to SE-0307 CGFloat/Double Interchangeable? #57543

Open
mattyoung opened this issue Sep 21, 2021 · 2 comments

Comments

@mattyoung
Copy link

Previous ID SR-15221
Radar rdar://problem/83413156
Original Reporter @mattyoung
Type New Feature
Additional Detail from JIRA
Votes 0
Component/s
Labels New Feature
Assignee None
Priority Medium

md5: 7a374a66d7abb2fb105bcb0ce72e99a9

Issue Description:

import SwiftUI

struct MyButtonStyle {
    let minWidth: Double?
}

extension View {
    func foo(minWidth: Double?) -> some View {
        EmptyView()
    }
}

struct FrameCGFloatAndDoubleXXX: View {
    static let width = CGFloat.zero
    let s = MyButtonStyle(minWidth: 2 * Self.width / 3)     // same expression as below, it's fine here

    var body: some View {
        foo(minWidth: 2 * Self.width)       // ok
        foo(minWidth: Self.width / 3)       // ok



        foo(minWidth: 2 * Self.width / 3)   // Error: Ambiguous use of operator '/'


        foo(minWidth: 2 * Self.width / 3.0)             // this is ok
        foo(minWidth: 2 * Self.width / (3 as Double))   // this is ok, so cannot have more than 1 int looking literals?
    }
}
@typesanitizer
Copy link

@swift-ci create

@mattyoung
Copy link
Author

Simpler example:

import SwiftUI

struct SomeView: View {
    let width: CGFloat = 0

    func foo(_ v: Double) -> some View {
        EmptyView()
    }

    // not ok
    var body: some View {
        foo(2 * width / 3)   // Error: Ambiguous use of operator '/'
    }

    // ok
    var body2: some View {
        foo(2 * width / 3) // yet this is ok
        return EmptyView()
    }
}

See: https://forums.swift.org/t/why-calling-swiftui-color-redblue-compiler-can-infer-param-type-is-double-but-calling-with-init-redblue-alpha-it-cannot-and-must-use-explicit-double-literal/52427/4

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants