Skip to content

Commit 3cb184a

Browse files
authored
Merge pull request #72877 from xedin/revert-subtype-with-sendable-changes-6.0
[6.0] Revert "[TypeChecker] TypeChecker::isSubtypeOf should recognize Sendable/@sendable subtyping"
2 parents bca5018 + 3881d50 commit 3cb184a

File tree

3 files changed

+33
-34
lines changed

3 files changed

+33
-34
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,22 +1068,8 @@ bool TypeChecker::typesSatisfyConstraint(Type type1, Type type2,
10681068
}
10691069

10701070
if (auto solution = cs.solveSingle()) {
1071-
const auto &score = solution->getFixedScore();
10721071
if (unwrappedIUO)
1073-
*unwrappedIUO = score.Data[SK_ForceUnchecked] > 0;
1074-
1075-
// Make sure that Sendable vs. no-Sendable mismatches are
1076-
// failures here to establish subtyping relationship
1077-
// (unlike in the solver where they are warnings until Swift 6).
1078-
if (kind == ConstraintKind::Subtype) {
1079-
if (score.Data[SK_MissingSynthesizableConformance] > 0)
1080-
return false;
1081-
1082-
if (llvm::any_of(solution->Fixes, [](const auto *fix) {
1083-
return fix->getKind() == FixKind::AddSendableAttribute;
1084-
}))
1085-
return false;
1086-
}
1072+
*unwrappedIUO = solution->getFixedScore().Data[SK_ForceUnchecked] > 0;
10871073

10881074
return true;
10891075
}

test/Concurrency/sendable_keypaths.swift

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,14 @@ do {
223223
fatalError()
224224
}
225225

226+
// TODO(rdar://125948508): This shouldn't be ambiguous (@Sendable version should be preferred)
226227
func test() -> KeyPath<String, Int> {
227-
true ? kp() : kp() // Ok
228+
true ? kp() : kp() // expected-error {{type of expression is ambiguous without a type annotation}}
228229
}
229230

230231
func forward<T>(_ v: T) -> T { v }
231-
let _: KeyPath<String, Int> = forward(kp()) // Ok
232+
// TODO(rdar://125948508): This shouldn't be ambiguous (@Sendable version should be preferred)
233+
let _: KeyPath<String, Int> = forward(kp()) // expected-error {{conflicting arguments to generic parameter 'T' ('any KeyPath<String, Int> & Sendable' vs. 'KeyPath<String, Int>')}}
232234
}
233235

234236
do {
@@ -238,3 +240,22 @@ do {
238240

239241
_ = \C<Int>.immutable as? ReferenceWritableKeyPath // Ok
240242
}
243+
244+
// Should be moved back to sendable_methods.swift once ambiguities are fixed
245+
do {
246+
struct Test {
247+
static func fn() {}
248+
static func otherFn() {}
249+
}
250+
251+
// TODO(rdar://125948508): This shouldn't be ambiguous (@Sendable version should be preferred)
252+
func fnRet(cond: Bool) -> () -> Void {
253+
cond ? Test.fn : Test.otherFn // expected-error {{type of expression is ambiguous without a type annotation}}
254+
}
255+
256+
func forward<T>(_: T) -> T {
257+
}
258+
259+
// TODO(rdar://125948508): This shouldn't be ambiguous (@Sendable version should be preferred)
260+
let _: () -> Void = forward(Test.fn) // expected-error {{conflicting arguments to generic parameter 'T' ('@Sendable () -> ()' vs. '() -> Void')}}
261+
}

test/Concurrency/sendable_methods.swift

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -229,23 +229,6 @@ do {
229229
}
230230
}
231231

232-
do {
233-
struct Test {
234-
static func fn() {}
235-
static func otherFn() {}
236-
}
237-
238-
func fnRet(cond: Bool) -> () -> Void {
239-
cond ? Test.fn : Test.otherFn // Ok
240-
}
241-
242-
func forward<T>(_: T) -> T {
243-
}
244-
245-
let _: () -> Void = forward(Test.fn) // Ok
246-
}
247-
248-
249232
func test_initializer_ref() {
250233
func test<T>(_: @Sendable (T, T) -> Array<T>) {
251234
}
@@ -277,3 +260,12 @@ do {
277260
}
278261
}
279262
}
263+
264+
// rdar://125932231 - incorrect `error: type of expression is ambiguous without a type annotation`
265+
do {
266+
class C {}
267+
268+
func test(c: C) -> (any Sendable)? {
269+
true ? nil : c // Ok
270+
}
271+
}

0 commit comments

Comments
 (0)