Passing `CGFloat` to `Double?`: perfectly correct expression gets "Ambiguous use of operator '/'"

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 as CGFloat))   // this is ok, so cannot handle more than 1 literals?
    }
}

What's wrong? Something to do with how SE-0307: Allow interchangeable use of CGFloat and Double types work? or interaction with ViewBuilder? Type checker problem?

@xedin

https://bugs.swift.org/browse/SR-15221

2 Likes
Terms of Service

Privacy Policy

Cookie Policy