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-15218] Enhance interchangeable CGFloat/Double to allow interchange between optional #57540
Comments
@swift-ci create |
I think this can make an interesting StarterBug. |
Hi @xedin, what should I look at if I'm interested in fixing this but don't have familiarity with where this is handled or what the fix will look like? I'd like to figure out if I can do this before assigning it to myself. |
@amritpan This might be a bit tricky actually due to how conversion restrictions behave. CGFloat/Double conversion needs to wait until all Optional-to-Optional conversions are performed for a particular location, and if the optionality is the same on both sides (e.g. both types are no longer optional) allow Double/CGFloat conversion (Related methods are `matchTypes` and `simplifyRestrictedConstraintImpl` located in CSSimplify.cpp). This is relatively straight-forward to implement and it would result in a valid solution (you can double-check that using `-Xfrontend -debug-constraints` - more info about that @ https://github.com/apple/swift/blob/main/docs/DebuggingTheCompiler.md#debugging-the-type-checker). Next step is to add a number of implicit `.map` calls based on the number of `optional-to-optional` conversions performed for a given location during solution application (related code lives in CSApply.cpp - `coerceToType` method, you can search for ConversionRestrictionKind::DoubleToCGFloat to find relevant location). Here is another catch though - `ConstraintRestrictions` are not positional, so there is no way (currently) to determine how many did each location (identified by a ConstraintLocator) have, you'd have to change that to be able to insert appropriate number of `.map` calls or somehow figure out what was the optionality before first optional-to-optional conversion has been applied to a given location. |
Cannot convert value of type 'UnsafeMutablePointer<Double>' to expected argument type 'UnsafeMutablePointer<CGFloat>' extension Color {
var luminance: Double {
var (r, g, b, a): (Double, Double, Double, Double) = (0, 0, 0, 0)
UIColor(self).getRed(&r, green: &g, blue: &b, alpha: &a) // Cannot convert value of type 'UnsafeMutablePointer<Double>' to expected argument type 'UnsafeMutablePointer<CGFloat>'
return 0.2126 * r + 0.7152 * g + 0.0722 * b
}
} is this the same problem? Or something different? |
@mattyoung No, that is different and also not a problem, as it works as expected. It is logically impossible to make typed pointers to two types with possibly distinct representations in memory become interchangeable with each other. |
Looks like this is fixed: #40047 |
@mattyoung No, that is a tailored diagnostic to explain that this is not supported. |
@xedin Hello, I'm new to this project and tried working on this issue since it's a StarterBug. I went through the code with a debugger and did some experiments. I would like some help please.
|
@jreference Sorry, we shouldn't have added "good first issue" tag on this one. You'd need to be familiar with some inner working of the solver before attempting to fix it. |
Additional Detail from JIRA
md5: f6e45c4a9212f2077155f5dc1ee322a7
Issue Description:
Currently passing
Double?
to parameter ofCGFloat?
do not work. Please add enhancement to allow such. Additionally, allow multiple level of optionality. Basically allow this:Double?* <-> CGFloat?* (zero or more level of optionality)
See: https://forums.swift.org/t/why-double-can-pass-to-cgfloat-but-double-cannot/52217/5
The text was updated successfully, but these errors were encountered: