Skip to content

Commit 4a57d70

Browse files
committed
xxx
1 parent 36838d8 commit 4a57d70

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

lib/AST/ASTScopeCreation.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -959,11 +959,8 @@ AnnotatedInsertionPoint
959959
ConditionalClausePatternUseScope::expandAScopeThatCreatesANewInsertionPoint(
960960
ScopeCreator &scopeCreator) {
961961
auto *initializer = sec.getInitializer();
962-
if (!isa<ErrorExpr>(initializer)) {
963-
scopeCreator
964-
.constructExpandAndInsert<ConditionalClauseInitializerScope>(
965-
this, initializer);
966-
}
962+
scopeCreator.constructExpandAndInsert<ConditionalClauseInitializerScope>(
963+
this, initializer);
967964

968965
return {this,
969966
"Succeeding code must be in scope of conditional clause pattern bindings"};

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,6 +3155,10 @@ namespace {
31553155
case PatternKind::Expr: {
31563156
// We generate constraints for ExprPatterns in a separate pass. For
31573157
// now, just create a type variable.
3158+
auto *EP = cast<ExprPattern>(pattern);
3159+
EP->getSubExpr()->forEachUnresolvedVariable([&](VarDecl *VD) {
3160+
CS.setType(VD, ErrorType::get(CS.getASTContext()));
3161+
});
31583162
return setType(CS.createTypeVariable(CS.getConstraintLocator(locator),
31593163
TVO_CanBindToNoEscape));
31603164
}

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
855855
// FIXME: We shouldn't be leaving AST un-type-checked in invalid cases, we
856856
// ought to fix that and then change this to only consider IDE inspection.
857857
auto &ctx = CE->getASTContext();
858-
if (ctx.hadError() || ctx.SourceMgr.hasIDEInspectionTargetBuffer()) {
858+
if (ctx.SourceMgr.hasIDEInspectionTargetBuffer()) {
859859
target.markInvalid();
860860
return true;
861861
}

lib/Sema/TypeCheckStmt.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,12 +1092,14 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
10921092
auto &eval = getASTContext().evaluator;
10931093
auto *S =
10941094
evaluateOrDefault(eval, PreCheckReturnStmtRequest{RS, DC}, nullptr);
1095+
if (!S)
1096+
return nullptr;
10951097

10961098
// We do a cast here as it may have been turned into a FailStmt. We should
10971099
// return that without doing anything else.
1098-
RS = dyn_cast_or_null<ReturnStmt>(S);
1100+
RS = dyn_cast<ReturnStmt>(S);
10991101
if (!RS)
1100-
return S;
1102+
return visit(S);
11011103

11021104
auto TheFunc = AnyFunctionRef::fromDeclContext(DC);
11031105
assert(TheFunc && "Should have bailed from pre-check if this is None");
@@ -1778,16 +1780,26 @@ Stmt *PreCheckReturnStmtRequest::evaluate(Evaluator &evaluator, ReturnStmt *RS,
17781780
auto &ctx = DC->getASTContext();
17791781
auto fn = AnyFunctionRef::fromDeclContext(DC);
17801782

1783+
auto errorResult = [&]() -> Stmt * {
1784+
if (RS->hasResult()) {
1785+
auto *AE = new (ctx)
1786+
AssignExpr(new (ctx) DiscardAssignmentExpr(SourceLoc(), true),
1787+
SourceLoc(), RS->getResult(), true);
1788+
return BraceStmt::createImplicit(ctx, {AE});
1789+
}
1790+
return nullptr;
1791+
};
1792+
17811793
// Not valid outside of a function.
17821794
if (!fn) {
17831795
ctx.Diags.diagnose(RS->getReturnLoc(), diag::return_invalid_outside_func);
1784-
return nullptr;
1796+
return errorResult();
17851797
}
17861798

17871799
// If the return is in a defer, then it isn't valid either.
17881800
if (isDefer(DC)) {
17891801
ctx.Diags.diagnose(RS->getReturnLoc(), diag::jump_out_of_defer, "return");
1790-
return nullptr;
1802+
return errorResult();
17911803
}
17921804

17931805
// The rest of the checks only concern return statements with results.

0 commit comments

Comments
 (0)