Skip to content

Commit 3530dc6

Browse files
committed
[Concurrency] Allow synchronous witnesses to satisfy 'async' requirements.
1 parent f46ad6c commit 3530dc6

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,8 @@ swift::matchWitness(
713713
}
714714

715715
// If the witness is 'async', the requirement must be.
716-
if (witnessFnType->getExtInfo().isAsync() !=
717-
reqFnType->getExtInfo().isAsync()) {
716+
if (witnessFnType->getExtInfo().isAsync() &&
717+
!reqFnType->getExtInfo().isAsync()) {
718718
return RequirementMatch(witness, MatchKind::AsyncConflict);
719719
}
720720

test/SILGen/async_conversion.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,13 @@ func test() {
1111
// CHECK: partial_apply [callee_guaranteed] [[THUNK]]([[THICK_F]]) : $@convention(thin) @async (Int, @guaranteed String, @guaranteed @callee_guaranteed (Int, @guaranteed String) -> @owned Optional<String>) -> @owned Optional<String>
1212
let _: (Int, String) async -> String? = f
1313
}
14+
15+
protocol P {
16+
func f(_: Int, _: String) async -> String?
17+
}
18+
19+
struct X: P {
20+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s4test1XVAA1PA2aDP1fySSSgSi_SStYFTW : $@convention(witness_method: P) @async (Int, @guaranteed String, @in_guaranteed X) -> @owned Optional<String>
21+
// CHECK: function_ref @$s4test1XV1fySSSgSi_SStF : $@convention(method) (Int, @guaranteed String, X) -> @owned Optional<String>
22+
func f(_: Int, _: String) -> String? { nil }
23+
}

test/decl/func/async.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ struct ConformsToP1: P1 { // expected-error{{type 'ConformsToP1' does not confor
3333
}
3434

3535
protocol P2 {
36-
func f() async // expected-note{{protocol requires function 'f()' with type '() async -> ()'; do you want to add a stub?}}
36+
func f() async
3737
}
3838

39-
struct ConformsToP2: P2 { // expected-error{{type 'ConformsToP2' does not conform to protocol 'P2'}}
40-
func f() { } // expected-note{{candidate is not 'async', but protocol requirement is}}
39+
struct ConformsToP2: P2 {
40+
func f() { } // okay
4141
}

0 commit comments

Comments
 (0)