Skip to content

Commit dff5786

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.
1 parent e24d18c commit dff5786

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
@@ -978,6 +978,10 @@ enum ScoreKind: unsigned int {
978978
SK_ValueToPointerConversion,
979979
/// A closure/function conversion to an autoclosure parameter.
980980
SK_FunctionToAutoClosureConversion,
981+
/// A type with a missing conformance(s) that has be synthesized
982+
/// or diagnosed later, such types are allowed to appear in
983+
/// a valid solution.
984+
SK_MissingSynthesizableConformance,
981985
/// An unapplied reference to a function. The purpose of this
982986
/// score bit is to prune overload choices that are functions
983987
/// when a solution has already been found using property.
@@ -988,12 +992,8 @@ enum ScoreKind: unsigned int {
988992
/// ambiguity tie-breakers should go after this; anything else
989993
/// should be added above.
990994
SK_UnappliedFunction,
991-
/// A type with a missing conformance(s) that has be synthesized
992-
/// or diagnosed later, such types are allowed to appear in
993-
/// a valid solution.
994-
SK_MissingSynthesizableConformance,
995995

996-
SK_LastScoreKind = SK_MissingSynthesizableConformance,
996+
SK_LastScoreKind = SK_UnappliedFunction,
997997
};
998998

999999
/// 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)