mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CSApply] Load l-value before wrapping it in try expression
Just like `try?` other types of try - `try` and `try!` have to load the value before using it. Resolve: rdar://78102266
This commit is contained in:
@@ -3412,7 +3412,21 @@ namespace {
|
||||
}
|
||||
|
||||
Expr *visitAnyTryExpr(AnyTryExpr *expr) {
|
||||
cs.setType(expr, cs.getType(expr->getSubExpr()));
|
||||
auto *subExpr = expr->getSubExpr();
|
||||
auto type = simplifyType(cs.getType(subExpr));
|
||||
|
||||
// Let's load the value associated with this try.
|
||||
if (type->hasLValueType()) {
|
||||
subExpr = coerceToType(subExpr, type->getRValueType(),
|
||||
cs.getConstraintLocator(subExpr));
|
||||
|
||||
if (!subExpr)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
cs.setType(expr, cs.getType(subExpr));
|
||||
expr->setSubExpr(subExpr);
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// RUN: %target-swift-frontend %s -typecheck
|
||||
|
||||
struct Info {
|
||||
}
|
||||
|
||||
class Test {
|
||||
var info: Info = Info()
|
||||
|
||||
init() throws {}
|
||||
}
|
||||
|
||||
_ = try Test().info // Ok
|
||||
_ = try! Test().info // Ok
|
||||
Reference in New Issue
Block a user