Skip to content

Commit 8a918e2

Browse files
committed
[CSOptimizer] Don't optimize (implicit) calls with code completion arguments
`containsIDEInspectionTarget` doesn't work for implicit argument lists, but luckily implicit code completion expressions cannot be injected into arguments, so we can check whether whether they appear at an argument position and prevent optimization.
1 parent deca9b6 commit 8a918e2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/Sema/CSOptimizer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,18 @@ static Constraint *determineBestChoicesInContext(
167167
applicableFn.get()->getFirstType()->getAs<FunctionType>();
168168

169169
auto argumentList = cs.getArgumentList(applicableFn.get()->getLocator());
170-
if (!argumentList || cs.containsIDEInspectionTarget(argumentList))
170+
if (!argumentList)
171171
return nullptr;
172172

173+
for (const auto &argument : *argumentList) {
174+
if (auto *expr = argument.getExpr()) {
175+
// Directly `<#...#>` or has one inside.
176+
if (isa<CodeCompletionExpr>(expr) ||
177+
cs.containsIDEInspectionTarget(expr))
178+
return nullptr;
179+
}
180+
}
181+
173182
SmallVector<FunctionType::Param, 8> argsWithLabels;
174183
{
175184
argsWithLabels.append(argFuncType->getParams().begin(),

test/IDE/complete_operators.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func testPostfix6() {
5252
func testPostfix7() {
5353
1 + 2 * 3.0#^POSTFIX_7^#
5454
}
55-
// POSTFIX_7: Decl[PostfixOperatorFunction]/CurrModule: ***[#Double#]
55+
// POSTFIX_7: Decl[PostfixOperatorFunction]/CurrModule/TypeRelation[Convertible]: ***[#Double#]
5656

5757
func testPostfix8(x: S) {
5858
x#^POSTFIX_8^#

0 commit comments

Comments
 (0)