[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:
Pavel Yaskevich
2023-11-01 10:44:32 -07:00
parent e24d18c8d4
commit dff578638a
2 changed files with 26 additions and 5 deletions

View File

@@ -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.

View File

@@ -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)
}
}