mirror of
https://github.com/apple/swift.git
synced 2026-10-28 21:15:56 +01:00
It looks like6b504ff790regressed a common code pattern we used to accept, where people insert a useless CGFloat(...) conversion of an argument value which is expected to be a Double: import SwiftUI func test(shape: any Shape, color: Color, x: Double) { _ = shape.fill(color.opacity(CGFloat(x))) } This seems to be prohibited by https://github.com/swiftlang/swift-evolution/blob/main/proposals/0307-allow-interchangeable-use-of-double-cgfloat-types.md, but the exact wording there is unclear. The proposal suggests that converting the argument to CGFloat.init is prohibited, but that would have no meaningful effect; it seems what was meant is that we want to prohibit converting the _result_. However, enforcing that rule more strictly, by simplifying the locator, broke this non-sensical but common code pattern. Since simplifying the locator was itself a fix for an earlier regression fromb365a5e2ec, which was itself a fix for a regression that only came up with -solver-enable-promote-supertypes, I'm going to put both of those changes behind -solver-enable-promote-supertypes until I can figure out a consistent set of rules that handle all existing code we've seen so far. Fixes rdar://190435916.
41 lines
2.0 KiB
Swift
41 lines
2.0 KiB
Swift
// RUN: %target-swift-emit-silgen %s -solver-enable-promote-supertypes | %FileCheck %s
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
import Foundation
|
|
import CoreGraphics
|
|
|
|
func f1(_ x: Double) {}
|
|
func g1() -> Double { 0 }
|
|
|
|
func f2(_ x: CGFloat) {}
|
|
func g2() -> CGFloat { 0 }
|
|
|
|
func test() {
|
|
let _: (CGFloat) -> () = f1
|
|
let _: () -> CGFloat = g1
|
|
|
|
let _: (CGFloat) -> () = f2
|
|
let _: () -> CGFloat = g2
|
|
}
|
|
|
|
// CHECK-LABEL: sil shared [transparent] [serialized] [reabstraction_thunk] [ossa] @$sSdIegy_12CoreGraphics7CGFloatVIegy_TR : $@convention(thin) (CGFloat, @guaranteed @callee_guaranteed (Double) -> ()) -> () {
|
|
// CHECK: bb0(%0 : $CGFloat, %1 : @guaranteed $@callee_guaranteed (Double) -> ()):
|
|
// CHECK: [[META:%.*]] = metatype $@thin Double.Type
|
|
// CHECK: [[INIT:%.*]] = function_ref @$sSd12CoreGraphicsEySdAA7CGFloatVcfC : $@convention(method) (CGFloat, @thin Double.Type) -> Double
|
|
// CHECK: [[ARG:%.*]] = apply [[INIT]](%0, [[META]]) : $@convention(method) (CGFloat, @thin Double.Type) -> Double
|
|
// CHECK: apply %1([[ARG]]) : $@callee_guaranteed (Double) -> ()
|
|
// CHECK: return
|
|
|
|
// CHECK-LABEL: sil [transparent] [serialized] [available {{.*}}] @$sSd12CoreGraphicsEySdAA7CGFloatVcfC : $@convention(method) (CGFloat, @thin Double.Type) -> Double
|
|
|
|
// CHECK-LABEL: sil shared [transparent] [serialized] [reabstraction_thunk] [ossa] @$sSdIegd_12CoreGraphics7CGFloatVIegd_TR : $@convention(thin) (@guaranteed @callee_guaranteed () -> Double) -> CGFloat {
|
|
// CHECK: bb0(%0 : @guaranteed $@callee_guaranteed () -> Double):
|
|
// CHECK: [[RESULT:%.*]] = apply %0() : $@callee_guaranteed () -> Double
|
|
// CHECK: [[META:%.*]] = metatype $@thin CGFloat.Type
|
|
// CHECK: [[INIT:%.*]] = function_ref @$s12CoreGraphics7CGFloatVyACSdcfC : $@convention(method) (Double, @thin CGFloat.Type) -> CGFloat
|
|
// CHECK: [[RET:%.*]] = apply [[INIT]]([[RESULT]], [[META]]) : $@convention(method) (Double, @thin CGFloat.Type) -> CGFloat
|
|
// CHECK: return [[RET]]
|
|
|
|
// CHECK-LABEL: sil [transparent] [serialized] [available {{.*}}] @$s12CoreGraphics7CGFloatVyACSdcfC : $@convention(method) (Double, @thin CGFloat.Type) -> CGFloat
|