Skip to content
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
1 change: 1 addition & 0 deletions include/swift/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,7 @@ class SyntacticElementTargetRewriter {

virtual void addLocalDeclToTypeCheck(Decl *D) = 0;

[[nodiscard]]
virtual std::optional<SyntacticElementTarget>
rewriteTarget(SyntacticElementTarget target) = 0;

Expand Down
27 changes: 18 additions & 9 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8949,7 +8949,8 @@ namespace {
PreWalkResult<Expr *> walkToExprPre(Expr *expr) override {
// For closures, update the parameter types and check the body.
if (auto closure = dyn_cast<ClosureExpr>(expr)) {
rewriteFunction(closure);
if (rewriteFunction(closure))
return Action::Stop();

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

if (auto *SVE = dyn_cast<SingleValueStmtExpr>(expr)) {
rewriteSingleValueStmtExpr(SVE);
if (rewriteSingleValueStmtExpr(SVE))
return Action::Stop();
return Action::SkipNode(SVE);
}

if (auto tap = dyn_cast_or_null<TapExpr>(expr)) {
rewriteTapExpr(tap);
if (rewriteTapExpr(tap))
return Action::Stop();
return Action::SkipNode(tap);
}

if (auto captureList = dyn_cast<CaptureListExpr>(expr)) {
// Rewrite captures.
for (const auto &capture : captureList->getCaptureList()) {
(void)rewriteTarget(SyntacticElementTarget(capture.PBD));
if (!rewriteTarget(SyntacticElementTarget(capture.PBD)))
return Action::Stop();
}
}

Expand All @@ -9000,31 +9004,36 @@ namespace {
return Action::SkipNode();
}

NullablePtr<Pattern>
rewritePattern(Pattern *pattern, DeclContext *DC);
[[nodiscard]]
NullablePtr<Pattern> rewritePattern(Pattern *pattern, DeclContext *DC);

/// Rewrite the target, producing a new target.
[[nodiscard]]
std::optional<SyntacticElementTarget>
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
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/CSSyntacticElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
}
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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