diff --git a/include/swift/Sema/ConstraintSystem.h b/include/swift/Sema/ConstraintSystem.h index e2356f7e60546..4f7e2f0b376e5 100644 --- a/include/swift/Sema/ConstraintSystem.h +++ b/include/swift/Sema/ConstraintSystem.h @@ -2131,6 +2131,7 @@ class SyntacticElementTargetRewriter { virtual void addLocalDeclToTypeCheck(Decl *D) = 0; + [[nodiscard]] virtual std::optional rewriteTarget(SyntacticElementTarget target) = 0; diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index 2e6d5e1f62444..900375b327fd6 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -8949,7 +8949,8 @@ namespace { PreWalkResult walkToExprPre(Expr *expr) override { // For closures, update the parameter types and check the body. if (auto closure = dyn_cast(expr)) { - rewriteFunction(closure); + if (rewriteFunction(closure)) + return Action::Stop(); if (AnyFunctionRef(closure).hasExternalPropertyWrapperParameters()) { auto *thunkTy = Rewriter.cs.getType(closure)->castTo(); @@ -8962,19 +8963,22 @@ namespace { } if (auto *SVE = dyn_cast(expr)) { - rewriteSingleValueStmtExpr(SVE); + if (rewriteSingleValueStmtExpr(SVE)) + return Action::Stop(); return Action::SkipNode(SVE); } if (auto tap = dyn_cast_or_null(expr)) { - rewriteTapExpr(tap); + if (rewriteTapExpr(tap)) + return Action::Stop(); return Action::SkipNode(tap); } if (auto captureList = dyn_cast(expr)) { // Rewrite captures. for (const auto &capture : captureList->getCaptureList()) { - (void)rewriteTarget(SyntacticElementTarget(capture.PBD)); + if (!rewriteTarget(SyntacticElementTarget(capture.PBD))) + return Action::Stop(); } } @@ -9000,31 +9004,36 @@ namespace { return Action::SkipNode(); } - NullablePtr - rewritePattern(Pattern *pattern, DeclContext *DC); + [[nodiscard]] + NullablePtr rewritePattern(Pattern *pattern, DeclContext *DC); /// Rewrite the target, producing a new target. + [[nodiscard]] std::optional rewriteTarget(SyntacticElementTarget target) override; /// Rewrite the function for the given solution. /// /// \returns true if an error occurred. + [[nodiscard]] bool rewriteFunction(AnyFunctionRef fn) { return Rewriter.cs.applySolution(fn, *this); } + [[nodiscard]] bool rewriteSingleValueStmtExpr(SingleValueStmtExpr *SVE) { return Rewriter.cs.applySolutionToSingleValueStmt(SVE, *this); } - void rewriteTapExpr(TapExpr *tap) { + [[nodiscard]] + bool rewriteTapExpr(TapExpr *tap) { // First, let's visit the tap expression itself // and set all of the inferred types. - Rewriter.visitTapExpr(tap); + if (!Rewriter.visitTapExpr(tap)) + return true; // Now, let's apply solution to the body - (void)Rewriter.cs.applySolutionToBody(tap, *this); + return Rewriter.cs.applySolutionToBody(tap, *this); } }; } // end anonymous namespace diff --git a/lib/Sema/CSSyntacticElement.cpp b/lib/Sema/CSSyntacticElement.cpp index 9f3aaf45d705c..9fc7fb6a92e5b 100644 --- a/lib/Sema/CSSyntacticElement.cpp +++ b/lib/Sema/CSSyntacticElement.cpp @@ -1977,8 +1977,8 @@ class SyntacticElementSolutionApplication // Check to see if the sequence expr is throwing (in async context), // if so require the stmt to have a `try`. - hadError |= diagnoseUnhandledThrowsInAsyncContext( - context.getAsDeclContext(), forEachStmt); + diagnoseUnhandledThrowsInAsyncContext(context.getAsDeclContext(), + forEachStmt); return forEachStmt; } diff --git a/validation-test/compiler_crashers/DiagnoseWalker-checkUseOfMetaTypeName-a87df2.swift b/validation-test/compiler_crashers_fixed/DiagnoseWalker-checkUseOfMetaTypeName-a87df2.swift similarity index 87% rename from validation-test/compiler_crashers/DiagnoseWalker-checkUseOfMetaTypeName-a87df2.swift rename to validation-test/compiler_crashers_fixed/DiagnoseWalker-checkUseOfMetaTypeName-a87df2.swift index e8e05a7b28632..dafaee82181e0 100644 --- a/validation-test/compiler_crashers/DiagnoseWalker-checkUseOfMetaTypeName-a87df2.swift +++ b/validation-test/compiler_crashers_fixed/DiagnoseWalker-checkUseOfMetaTypeName-a87df2.swift @@ -1,5 +1,5 @@ // {"kind":"typecheck","signature":"diagSyntacticUseRestrictions(swift::Expr const*, swift::DeclContext const*, bool)::DiagnoseWalker::checkUseOfMetaTypeName(swift::Expr*)","signatureAssert":"Assertion failed: (Ptr && \"Cannot dereference a null Type!\"), function operator->"} -// RUN: not --crash %target-swift-frontend -typecheck %s +// RUN: not %target-swift-frontend -typecheck %s protocol a : Equatable, ExpressibleByStringLiteral { } { diff --git a/validation-test/compiler_crashers/ExprPatternMatchRequest-evaluate-50b525.swift b/validation-test/compiler_crashers_fixed/ExprPatternMatchRequest-evaluate-50b525.swift similarity index 83% rename from validation-test/compiler_crashers/ExprPatternMatchRequest-evaluate-50b525.swift rename to validation-test/compiler_crashers_fixed/ExprPatternMatchRequest-evaluate-50b525.swift index 5b4bb7834f1e7..0c5d08e063345 100644 --- a/validation-test/compiler_crashers/ExprPatternMatchRequest-evaluate-50b525.swift +++ b/validation-test/compiler_crashers_fixed/ExprPatternMatchRequest-evaluate-50b525.swift @@ -1,3 +1,3 @@ // {"kind":"typecheck","signature":"swift::ExprPatternMatchRequest::evaluate(swift::Evaluator&, swift::ExprPattern const*) const","signatureAssert":"Assertion failed: (EP->isResolved() && \"Must only be queried once resolved\"), function evaluate"} -// RUN: not --crash %target-swift-frontend -typecheck %s +// RUN: not %target-swift-frontend -typecheck %s enum a { b(c : a){{guard case.b = c