Skip to content

[Sema] Set ReturnStmt result even if type-checking fails #83096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/Sema/TypeCheckStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,9 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
if (resultTarget) {
RS->setResult(resultTarget->getAsExpr());
} else {
// Update the expression even if type-checking failed as e.g pre-checking
// may have folded a sequence expr.
RS->setResult(target.getAsExpr());
tryDiagnoseUnnecessaryCastOverOptionSet(getASTContext(), RS->getResult(),
ResultTy);
}
Expand Down
6 changes: 6 additions & 0 deletions validation-test/IDE/crashers_fixed/59ed4db5bf91f452.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// {"kind":"complete","original":"089853e1","signature":"swift::TypeChecker::typeCheckForCodeCompletion(swift::constraints::SyntacticElementTarget&, bool, llvm::function_ref<void (swift::constraints::Solution const&)>)"}
// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
struct a {
b:
func c -> UInt32 {
0 ^ b#^^#