@@ -406,8 +406,7 @@ static BinaryExpr *getCompositionExpr(Expr *expr) {
406406// / returning the resultant expression. Context is the DeclContext used
407407// / for the lookup.
408408Expr *TypeChecker::resolveDeclRefExpr (UnresolvedDeclRefExpr *UDRE,
409- DeclContext *DC,
410- bool replaceInvalidRefsWithErrors) {
409+ DeclContext *DC) {
411410 // Process UnresolvedDeclRefExpr by doing an unqualified lookup.
412411 DeclNameRef Name = UDRE->getName ();
413412 SourceLoc Loc = UDRE->getLoc ();
@@ -431,10 +430,10 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
431430 LookupName = DeclNameRef (lookupName);
432431 }
433432
433+ auto &Context = DC->getASTContext ();
434+
434435 auto errorResult = [&]() -> Expr * {
435- if (replaceInvalidRefsWithErrors)
436- return new (DC->getASTContext ()) ErrorExpr (UDRE->getSourceRange ());
437- return UDRE;
436+ return new (Context) ErrorExpr (UDRE->getSourceRange ());
438437 };
439438
440439 // Perform standard value name lookup.
@@ -449,8 +448,6 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
449448 bool AllDeclRefs = true ;
450449 SmallVector<ValueDecl*, 4 > ResultValues;
451450
452- auto &Context = DC->getASTContext ();
453-
454451 // First, look for a local binding in scope.
455452 if (Loc.isValid () && !Name.isOperator ()) {
456453 ASTScope::lookupLocalDecls (DC->getParentSourceFile (),
@@ -487,8 +484,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
487484 Context.Diags .diagnose (Loc, diag::use_local_before_declaration, Name);
488485 Context.Diags .diagnose (innerDecl, diag::decl_declared_here,
489486 localDeclAfterUse);
490- Expr *error = new (Context) ErrorExpr (UDRE->getSourceRange ());
491- return error;
487+ return errorResult ();
492488 }
493489
494490 Lookup.shiftDownResults ();
@@ -705,7 +701,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
705701 UDRE->getRefKind () == DeclRefKind::BinaryOperator
706702 ? 0
707703 : UDRE->getRefKind () == DeclRefKind::PrefixOperator ? 1 : 2 );
708- return new (Context) ErrorExpr (UDRE-> getSourceRange () );
704+ return errorResult ( );
709705 }
710706
711707 // For operators, sort the results so that non-generic operations come
@@ -844,7 +840,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
844840 auto *Decl = Result.getValueDecl ();
845841 Context.Diags .diagnose (Decl, diag::decl_declared_here, Decl);
846842 }
847- return new (Context) ErrorExpr (UDRE-> getSourceRange () );
843+ return errorResult ( );
848844}
849845
850846// / If an expression references 'self.init' or 'super.init' in an
@@ -1036,10 +1032,6 @@ namespace {
10361032
10371033 Expr *ParentExpr;
10381034
1039- // / Indicates whether pre-check is allowed to insert
1040- // / implicit `ErrorExpr` in place of invalid references.
1041- bool UseErrorExprs;
1042-
10431035 // / A stack of expressions being walked, used to determine where to
10441036 // / insert RebindSelfInConstructorExpr nodes.
10451037 llvm::SmallVector<Expr *, 8 > ExprStack;
@@ -1107,10 +1099,8 @@ namespace {
11071099 void markAcceptableDiscardExprs (Expr *E);
11081100
11091101 public:
1110- PreCheckExpression (DeclContext *dc, Expr *parent,
1111- bool replaceInvalidRefsWithErrors)
1112- : Ctx(dc->getASTContext ()), DC(dc), ParentExpr(parent),
1113- UseErrorExprs(replaceInvalidRefsWithErrors) {}
1102+ PreCheckExpression (DeclContext *dc, Expr *parent)
1103+ : Ctx(dc->getASTContext ()), DC(dc), ParentExpr(parent) {}
11141104
11151105 ASTContext &getASTContext () const { return Ctx; }
11161106
@@ -1232,8 +1222,7 @@ namespace {
12321222 new (Ctx) ErrorExpr (unresolved->getSourceRange ()));
12331223 }
12341224
1235- auto *refExpr =
1236- TypeChecker::resolveDeclRefExpr (unresolved, DC, UseErrorExprs);
1225+ auto *refExpr = TypeChecker::resolveDeclRefExpr (unresolved, DC);
12371226
12381227 // Check whether this is standalone `self` in init accessor, which
12391228 // is invalid.
@@ -2461,14 +2450,13 @@ Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) {
24612450 : nullptr ;
24622451}
24632452
2464- bool ConstraintSystem::preCheckTarget (SyntacticElementTarget &target,
2465- bool replaceInvalidRefsWithErrors) {
2453+ bool ConstraintSystem::preCheckTarget (SyntacticElementTarget &target) {
24662454 auto *DC = target.getDeclContext ();
24672455
24682456 bool hadErrors = false ;
24692457
24702458 if (auto *expr = target.getAsExpr ()) {
2471- hadErrors |= preCheckExpression (expr, DC, replaceInvalidRefsWithErrors );
2459+ hadErrors |= preCheckExpression (expr, DC);
24722460 // Even if the pre-check fails, expression still has to be re-set.
24732461 target.setExpr (expr);
24742462 }
@@ -2479,12 +2467,10 @@ bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target,
24792467 auto *sequenceExpr = stmt->getParsedSequence ();
24802468 auto *whereExpr = stmt->getWhere ();
24812469
2482- hadErrors |= preCheckExpression (sequenceExpr, DC,
2483- /* replaceInvalidRefsWithErrors=*/ true );
2470+ hadErrors |= preCheckExpression (sequenceExpr, DC);
24842471
24852472 if (whereExpr) {
2486- hadErrors |= preCheckExpression (whereExpr, DC,
2487- /* replaceInvalidRefsWithErrors=*/ true );
2473+ hadErrors |= preCheckExpression (whereExpr, DC);
24882474 }
24892475
24902476 // Update sequence and where expressions to pre-checked versions.
@@ -2501,12 +2487,11 @@ bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target,
25012487
25022488// / Pre-check the expression, validating any types that occur in the
25032489// / expression and folding sequence expressions.
2504- bool ConstraintSystem::preCheckExpression (Expr *&expr, DeclContext *dc,
2505- bool replaceInvalidRefsWithErrors) {
2490+ bool ConstraintSystem::preCheckExpression (Expr *&expr, DeclContext *dc) {
25062491 auto &ctx = dc->getASTContext ();
25072492 FrontendStatsTracer StatsTracer (ctx.Stats , " precheck-expr" , expr);
25082493
2509- PreCheckExpression preCheck (dc, expr, replaceInvalidRefsWithErrors );
2494+ PreCheckExpression preCheck (dc, expr);
25102495
25112496 // Perform the pre-check.
25122497 if (auto result = expr->walk (preCheck)) {
0 commit comments