Skip to content

Commit 25ef748

Browse files
committed
[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. (cherry picked from commit dff5786)
1 parent 7653ce2 commit 25ef748

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,10 @@ enum ScoreKind: unsigned int {
979979
SK_ValueToPointerConversion,
980980
/// A closure/function conversion to an autoclosure parameter.
981981
SK_FunctionToAutoClosureConversion,
982+
/// A type with a missing conformance(s) that has be synthesized
983+
/// or diagnosed later, such types are allowed to appear in
984+
/// a valid solution.
985+
SK_MissingSynthesizableConformance,
982986
/// An unapplied reference to a function. The purpose of this
983987
/// score bit is to prune overload choices that are functions
984988
/// when a solution has already been found using property.
@@ -989,12 +993,8 @@ enum ScoreKind: unsigned int {
989993
/// ambiguity tie-breakers should go after this; anything else
990994
/// should be added above.
991995
SK_UnappliedFunction,
992-
/// A type with a missing conformance(s) that has be synthesized
993-
/// or diagnosed later, such types are allowed to appear in
994-
/// a valid solution.
995-
SK_MissingSynthesizableConformance,
996996

997-
SK_LastScoreKind = SK_MissingSynthesizableConformance,
997+
SK_LastScoreKind = SK_UnappliedFunction,
998998
};
999999

10001000
/// The number of score kinds.

test/Concurrency/sendable_disambiguation.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,24 @@ do {
2525
_ = SendableOnly(value: v) // Ok
2626
}
2727
}
28+
29+
do {
30+
class K {
31+
func value() {}
32+
}
33+
34+
struct X {
35+
var fn: (Int) -> K
36+
func fn(_: Int) -> Int { 42 }
37+
}
38+
39+
func sendable<T>(_ fn: (Int) -> T) -> T { fn(42) }
40+
func sendable<T: Sendable>(_ fn: (Int) -> T) -> T { fn(0) }
41+
42+
func test(x: X) {
43+
let res = sendable(x.fn) // Ok (non-ambiguous and non-Sendable overload)
44+
res.value() // To make sure that previous expression picks a property
45+
let _: K = sendable(x.fn) // Ok (picks `sendable<T>` with a property)
46+
let _: Int = sendable(x.fn) // Ok (picks `sendable<T: Sendable>` with a method)
47+
}
48+
}

0 commit comments

Comments
 (0)