Skip to content

Commit 5901cd1

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 6e8a581 commit 5901cd1

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
@@ -482,6 +482,11 @@ TypeChecker::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
482482
// Build temporary expression to typecheck.
483483
// We allocate these expressions on the stack because we know they can't
484484
// escape and there isn't a better way to allocate scratch Expr nodes.
485+
486+
// Use a placeholder expr for the LHS argument to avoid sending
487+
// a pre-type-checked AST through the constraint system.
488+
OpaqueValueExpr argExpr(LHS->getSourceRange(), LHSTy,
489+
/*isPlaceholder=*/true);
485490
UnresolvedDeclRefExpr UDRE(DeclNameRef(opName), refKind, DeclNameLoc(Loc));
486491
auto *opExpr = TypeChecker::resolveDeclRefExpr(
487492
&UDRE, DC, /*replaceInvalidRefsWithErrors=*/true);
@@ -493,7 +498,7 @@ TypeChecker::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
493498
// (declref_expr name=<opName>)
494499
// (argument_list
495500
// (<LHS>)))
496-
auto *postfixExpr = PostfixUnaryExpr::create(ctx, opExpr, LHS);
501+
auto *postfixExpr = PostfixUnaryExpr::create(ctx, opExpr, &argExpr);
497502
return getTypeOfCompletionOperatorImpl(DC, postfixExpr, referencedDecl);
498503
}
499504

@@ -504,7 +509,7 @@ TypeChecker::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
504509
// (<LHS>)
505510
// (code_completion_expr)))
506511
CodeCompletionExpr dummyRHS(Loc);
507-
auto *binaryExpr = BinaryExpr::create(ctx, LHS, opExpr, &dummyRHS,
512+
auto *binaryExpr = BinaryExpr::create(ctx, &argExpr, opExpr, &dummyRHS,
508513
/*implicit*/ true);
509514
return getTypeOfCompletionOperatorImpl(DC, binaryExpr, referencedDecl);
510515
}

0 commit comments

Comments
 (0)