Skip to content

Commit 31245aa

Browse files
authored
[Sema] Check hasResult() before getResult() from ReturnStmt (#5362)
Fixes compiler_crashers/28390-swift-expr-walk.swift
1 parent 8a9c8d5 commit 31245aa

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6703,9 +6703,11 @@ diagnoseAmbiguousMultiStatementClosure(ClosureExpr *closure) {
67036703
llvm::SaveAndRestore<DeclContext*> SavedDC(CS->DC, closure);
67046704

67056705
// Otherwise, we're ok to type check the subexpr.
6706-
auto returnedExpr =
6707-
typeCheckChildIndependently(RS->getResult(),
6708-
TCC_AllowUnresolvedTypeVariables);
6706+
Expr *returnedExpr = nullptr;
6707+
if (RS->hasResult())
6708+
returnedExpr =
6709+
typeCheckChildIndependently(RS->getResult(),
6710+
TCC_AllowUnresolvedTypeVariables);
67096711

67106712
// If we found a type, presuppose it was the intended result and insert a
67116713
// fixit hint.

validation-test/compiler_crashers/28390-swift-expr-walk.swift renamed to validation-test/compiler_crashers_fixed/28390-swift-expr-walk.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// See http://swift.org/LICENSE.txt for license information
66
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -parse
8+
// RUN: not %target-swift-frontend %s -parse
99
// REQUIRES: asserts
1010
.h={return
1111
class c

0 commit comments

Comments
 (0)