Skip to content

Commit 3523a94

Browse files
committed
[Sema]Coerce to rvalue when withoutActuallyEscaping receives an lvalue argument
1 parent a6458c7 commit 3523a94

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8217,7 +8217,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
82178217
// Resolve into a MakeTemporarilyEscapableExpr.
82188218
auto *args = apply->getArgs();
82198219
assert(args->size() == 2 && "should have two arguments");
8220-
auto *nonescaping = args->getExpr(0);
8220+
auto *nonescaping = cs.coerceToRValue(args->getExpr(0));
82218221
auto *body = args->getExpr(1);
82228222
auto bodyTy = cs.getType(body)->getWithoutSpecifierType();
82238223
auto bodyFnTy = bodyTy->castTo<FunctionType>();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
func noEscapeWAE(f: () -> Void) {
4+
withoutActuallyEscaping(f) { $0() }
5+
}
6+
7+
func escapingWAE(f: @escaping () -> Void) {
8+
withoutActuallyEscaping(f) { $0() }
9+
}
10+
11+
func inoutWAE(f: inout () -> Void) {
12+
withoutActuallyEscaping(f) { $0() }
13+
}
14+
15+
func rethrowThroughInoutWAE(f: inout () throws -> Void) throws {
16+
try withoutActuallyEscaping(f) { try $0() }
17+
}
18+
19+
func consumingWAE(f: consuming @escaping () -> Void) {
20+
withoutActuallyEscaping(f) { $0() }
21+
}
22+
23+
func rethrowThroughConsumingWAE(f: consuming @escaping () throws -> Void) throws {
24+
try withoutActuallyEscaping(f) { try $0() }
25+
}
26+
27+
func sendingEscapingAsyncWAE(f: sending @escaping () async -> Void) {
28+
await withoutActuallyEscaping(f) { await $0() }
29+
}
30+
31+
func rethrowThroughSendingEscapingAsyncWAE(f: sending @escaping () async throws -> Void) throws {
32+
try await withoutActuallyEscaping(f) { try await $0() }
33+
}
34+
35+
func sendingNoEscapeAsyncWAE(f: sending () async -> Void) {
36+
await withoutActuallyEscaping(f) { await $0() }
37+
}
38+
39+
func rethrowThroughSendingNoEscapeAsyncWAE(f: sending () async throws -> Void) throws {
40+
try await withoutActuallyEscaping(f) { try await $0() }
41+
}

0 commit comments

Comments
 (0)