mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ConstraintSystem] Move SK_MissingSynthesizableConformance before SK_UnappliedFunction
This would make sure that if property is non-Sendable we'd pick a method if it's Sendable instead.
This commit is contained in:
@@ -978,6 +978,10 @@ enum ScoreKind: unsigned int {
|
||||
SK_ValueToPointerConversion,
|
||||
/// A closure/function conversion to an autoclosure parameter.
|
||||
SK_FunctionToAutoClosureConversion,
|
||||
/// A type with a missing conformance(s) that has be synthesized
|
||||
/// or diagnosed later, such types are allowed to appear in
|
||||
/// a valid solution.
|
||||
SK_MissingSynthesizableConformance,
|
||||
/// An unapplied reference to a function. The purpose of this
|
||||
/// score bit is to prune overload choices that are functions
|
||||
/// when a solution has already been found using property.
|
||||
@@ -988,12 +992,8 @@ enum ScoreKind: unsigned int {
|
||||
/// ambiguity tie-breakers should go after this; anything else
|
||||
/// should be added above.
|
||||
SK_UnappliedFunction,
|
||||
/// A type with a missing conformance(s) that has be synthesized
|
||||
/// or diagnosed later, such types are allowed to appear in
|
||||
/// a valid solution.
|
||||
SK_MissingSynthesizableConformance,
|
||||
|
||||
SK_LastScoreKind = SK_MissingSynthesizableConformance,
|
||||
SK_LastScoreKind = SK_UnappliedFunction,
|
||||
};
|
||||
|
||||
/// The number of score kinds.
|
||||
|
||||
@@ -25,3 +25,24 @@ do {
|
||||
_ = SendableOnly(value: v) // Ok
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
class K {
|
||||
func value() {}
|
||||
}
|
||||
|
||||
struct X {
|
||||
var fn: (Int) -> K
|
||||
func fn(_: Int) -> Int { 42 }
|
||||
}
|
||||
|
||||
func sendable<T>(_ fn: (Int) -> T) -> T { fn(42) }
|
||||
func sendable<T: Sendable>(_ fn: (Int) -> T) -> T { fn(0) }
|
||||
|
||||
func test(x: X) {
|
||||
let res = sendable(x.fn) // Ok (non-ambiguous and non-Sendable overload)
|
||||
res.value() // To make sure that previous expression picks a property
|
||||
let _: K = sendable(x.fn) // Ok (picks `sendable<T>` with a property)
|
||||
let _: Int = sendable(x.fn) // Ok (picks `sendable<T: Sendable>` with a method)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user