Skip to content

Commit 2fb40ab

Browse files
authored
Merge pull request #37598 from xedin/rdar-78102266
[CSApply] Load l-value before wrapping it in try expression
2 parents d93e5a3 + 8ab8b2e commit 2fb40ab

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3412,7 +3412,21 @@ namespace {
34123412
}
34133413

34143414
Expr *visitAnyTryExpr(AnyTryExpr *expr) {
3415-
cs.setType(expr, cs.getType(expr->getSubExpr()));
3415+
auto *subExpr = expr->getSubExpr();
3416+
auto type = simplifyType(cs.getType(subExpr));
3417+
3418+
// Let's load the value associated with this try.
3419+
if (type->hasLValueType()) {
3420+
subExpr = coerceToType(subExpr, type->getRValueType(),
3421+
cs.getConstraintLocator(subExpr));
3422+
3423+
if (!subExpr)
3424+
return nullptr;
3425+
}
3426+
3427+
cs.setType(expr, cs.getType(subExpr));
3428+
expr->setSubExpr(subExpr);
3429+
34163430
return expr;
34173431
}
34183432

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-frontend %s -typecheck
2+
3+
struct Info {
4+
}
5+
6+
class Test {
7+
var info: Info = Info()
8+
9+
init() throws {}
10+
}
11+
12+
_ = try Test().info // Ok
13+
_ = try! Test().info // Ok

0 commit comments

Comments
 (0)