Skip to content

Commit 8fd7a1d

Browse files
committed
Sema: Fix CSGen for ForceTryExpr
1 parent 5c6a526 commit 8fd7a1d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/Sema/CSGen.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,10 +2060,20 @@ namespace {
20602060
return valueTy;
20612061
}
20622062

2063-
Type visitAnyTryExpr(AnyTryExpr *expr) {
2063+
Type visitTryExpr(AnyTryExpr *expr) {
20642064
return CS.getType(expr->getSubExpr());
20652065
}
20662066

2067+
Type visitForceTryExpr(AnyTryExpr *expr) {
2068+
auto valueTy = CS.createTypeVariable(CS.getConstraintLocator(expr),
2069+
TVO_PrefersSubtypeBinding |
2070+
TVO_CanBindToNoEscape);
2071+
CS.addConstraint(ConstraintKind::Equal, valueTy,
2072+
CS.getType(expr->getSubExpr()),
2073+
CS.getConstraintLocator(expr));
2074+
return valueTy;
2075+
}
2076+
20672077
Type visitOptionalTryExpr(OptionalTryExpr *expr) {
20682078
auto valueTy = CS.createTypeVariable(CS.getConstraintLocator(expr),
20692079
TVO_PrefersSubtypeBinding |

validation-test/compiler_crashers_fixed/issue-85034.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-typecheck-verify-swift
2+
// RUN: %target-swift-emit-silgen %s
23

34
class C {
45
var x = 0
@@ -7,4 +8,5 @@ class C {
78
do {
89
let x = C()
910
let _ = (0, try x.x) // expected-warning {{no calls to throwing functions occur within 'try' expression}}
11+
let _ = (0, try! x.x) // expected-warning {{no calls to throwing functions occur within 'try' expression}}
1012
}

0 commit comments

Comments
 (0)