Skip to content

Commit cc4f685

Browse files
authored
Merge pull request swiftlang#37638 from xedin/rdar-78102266-5.5
[5.5][CSApply] Load l-value before wrapping it in try expression
2 parents c18ee6c + 0da2101 commit cc4f685

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
@@ -3417,7 +3417,21 @@ namespace {
34173417
}
34183418

34193419
Expr *visitAnyTryExpr(AnyTryExpr *expr) {
3420-
cs.setType(expr, cs.getType(expr->getSubExpr()));
3420+
auto *subExpr = expr->getSubExpr();
3421+
auto type = simplifyType(cs.getType(subExpr));
3422+
3423+
// Let's load the value associated with this try.
3424+
if (type->hasLValueType()) {
3425+
subExpr = coerceToType(subExpr, type->getRValueType(),
3426+
cs.getConstraintLocator(subExpr));
3427+
3428+
if (!subExpr)
3429+
return nullptr;
3430+
}
3431+
3432+
cs.setType(expr, cs.getType(subExpr));
3433+
expr->setSubExpr(subExpr);
3434+
34213435
return expr;
34223436
}
34233437

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)