Skip to content

Commit 29d9cf6

Browse files
committed
[CodeCompletion] Use an opaque value placeholder for operator arguments
in code completion to avoid sending a pre-type-checked AST through the constraint system.
1 parent f78fe28 commit 29d9cf6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,11 @@ TypeChecker::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
486486
// Build temporary expression to typecheck.
487487
// We allocate these expressions on the stack because we know they can't
488488
// escape and there isn't a better way to allocate scratch Expr nodes.
489+
490+
// Use a placeholder expr for the LHS argument to avoid sending
491+
// a pre-type-checked AST through the constraint system.
492+
OpaqueValueExpr argExpr(LHS->getSourceRange(), LHSTy,
493+
/*isPlaceholder=*/true);
489494
UnresolvedDeclRefExpr UDRE(DeclNameRef(opName), refKind, DeclNameLoc(Loc));
490495
auto *opExpr = TypeChecker::resolveDeclRefExpr(
491496
&UDRE, DC, /*replaceInvalidRefsWithErrors=*/true);
@@ -497,7 +502,7 @@ TypeChecker::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
497502
// (declref_expr name=<opName>)
498503
// (argument_list
499504
// (<LHS>)))
500-
auto *postfixExpr = PostfixUnaryExpr::create(ctx, opExpr, LHS);
505+
auto *postfixExpr = PostfixUnaryExpr::create(ctx, opExpr, &argExpr);
501506
return getTypeOfCompletionOperatorImpl(DC, postfixExpr, referencedDecl);
502507
}
503508

@@ -508,7 +513,7 @@ TypeChecker::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
508513
// (<LHS>)
509514
// (code_completion_expr)))
510515
CodeCompletionExpr dummyRHS(Loc);
511-
auto *binaryExpr = BinaryExpr::create(ctx, LHS, opExpr, &dummyRHS,
516+
auto *binaryExpr = BinaryExpr::create(ctx, &argExpr, opExpr, &dummyRHS,
512517
/*implicit*/ true);
513518
return getTypeOfCompletionOperatorImpl(DC, binaryExpr, referencedDecl);
514519
}

0 commit comments

Comments
 (0)