Skip to content

Commit 05e3d15

Browse files
committed
[CS] Propagate CSApply failures in a few more places
We had some cases where we weren't propagating failures to apply the solution, and as such weren't invalidating the resulting AST. Fix up these cases.
1 parent dc9f28f commit 05e3d15

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,6 +2131,7 @@ class SyntacticElementTargetRewriter {
21312131

21322132
virtual void addLocalDeclToTypeCheck(Decl *D) = 0;
21332133

2134+
[[nodiscard]]
21342135
virtual std::optional<SyntacticElementTarget>
21352136
rewriteTarget(SyntacticElementTarget target) = 0;
21362137

lib/Sema/CSApply.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8949,7 +8949,8 @@ namespace {
89498949
PreWalkResult<Expr *> walkToExprPre(Expr *expr) override {
89508950
// For closures, update the parameter types and check the body.
89518951
if (auto closure = dyn_cast<ClosureExpr>(expr)) {
8952-
rewriteFunction(closure);
8952+
if (rewriteFunction(closure))
8953+
return Action::Stop();
89538954

89548955
if (AnyFunctionRef(closure).hasExternalPropertyWrapperParameters()) {
89558956
auto *thunkTy = Rewriter.cs.getType(closure)->castTo<FunctionType>();
@@ -8962,19 +8963,22 @@ namespace {
89628963
}
89638964

89648965
if (auto *SVE = dyn_cast<SingleValueStmtExpr>(expr)) {
8965-
rewriteSingleValueStmtExpr(SVE);
8966+
if (rewriteSingleValueStmtExpr(SVE))
8967+
return Action::Stop();
89668968
return Action::SkipNode(SVE);
89678969
}
89688970

89698971
if (auto tap = dyn_cast_or_null<TapExpr>(expr)) {
8970-
rewriteTapExpr(tap);
8972+
if (rewriteTapExpr(tap))
8973+
return Action::Stop();
89718974
return Action::SkipNode(tap);
89728975
}
89738976

89748977
if (auto captureList = dyn_cast<CaptureListExpr>(expr)) {
89758978
// Rewrite captures.
89768979
for (const auto &capture : captureList->getCaptureList()) {
8977-
(void)rewriteTarget(SyntacticElementTarget(capture.PBD));
8980+
if (!rewriteTarget(SyntacticElementTarget(capture.PBD)))
8981+
return Action::Stop();
89788982
}
89798983
}
89808984

@@ -9000,31 +9004,36 @@ namespace {
90009004
return Action::SkipNode();
90019005
}
90029006

9003-
NullablePtr<Pattern>
9004-
rewritePattern(Pattern *pattern, DeclContext *DC);
9007+
[[nodiscard]]
9008+
NullablePtr<Pattern> rewritePattern(Pattern *pattern, DeclContext *DC);
90059009

90069010
/// Rewrite the target, producing a new target.
9011+
[[nodiscard]]
90079012
std::optional<SyntacticElementTarget>
90089013
rewriteTarget(SyntacticElementTarget target) override;
90099014

90109015
/// Rewrite the function for the given solution.
90119016
///
90129017
/// \returns true if an error occurred.
9018+
[[nodiscard]]
90139019
bool rewriteFunction(AnyFunctionRef fn) {
90149020
return Rewriter.cs.applySolution(fn, *this);
90159021
}
90169022

9023+
[[nodiscard]]
90179024
bool rewriteSingleValueStmtExpr(SingleValueStmtExpr *SVE) {
90189025
return Rewriter.cs.applySolutionToSingleValueStmt(SVE, *this);
90199026
}
90209027

9021-
void rewriteTapExpr(TapExpr *tap) {
9028+
[[nodiscard]]
9029+
bool rewriteTapExpr(TapExpr *tap) {
90229030
// First, let's visit the tap expression itself
90239031
// and set all of the inferred types.
9024-
Rewriter.visitTapExpr(tap);
9032+
if (!Rewriter.visitTapExpr(tap))
9033+
return true;
90259034

90269035
// Now, let's apply solution to the body
9027-
(void)Rewriter.cs.applySolutionToBody(tap, *this);
9036+
return Rewriter.cs.applySolutionToBody(tap, *this);
90289037
}
90299038
};
90309039
} // end anonymous namespace

validation-test/compiler_crashers/DiagnoseWalker-checkUseOfMetaTypeName-a87df2.swift renamed to validation-test/compiler_crashers_fixed/DiagnoseWalker-checkUseOfMetaTypeName-a87df2.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"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->"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
protocol a : Equatable, ExpressibleByStringLiteral {
44
}
55
{
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// {"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"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
enum a { b(c : a){{guard case.b = c

0 commit comments

Comments
 (0)