mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Completion] Fix trailing closure index check
`Res.FirstTrailingClosureIndex` is an index into the argument list, so comparing it against a parameter index is wrong. Instead, compare it against the argument index of the completion token, which is what we want to be checking. This ensures we don't try and offer argument completions for non-function default arguments. rdar://127760308
This commit is contained in:
@@ -50,7 +50,8 @@ bool ArgumentTypeCheckCompletionCallback::addPossibleParams(
|
||||
const AnyFunctionType::Param *TypeParam = &ParamsToPass[Idx];
|
||||
bool Required = !Res.DeclParamIsOptional[Idx];
|
||||
|
||||
if (Res.FirstTrailingClosureIndex && Idx > *Res.FirstTrailingClosureIndex &&
|
||||
if (Res.FirstTrailingClosureIndex &&
|
||||
Res.ArgIdx > *Res.FirstTrailingClosureIndex &&
|
||||
!TypeParam->getPlainType()
|
||||
->lookThroughAllOptionalTypes()
|
||||
->is<AnyFunctionType>()) {
|
||||
|
||||
@@ -18,6 +18,40 @@ func testGlobalFunc() {
|
||||
// GLOBALFUNC_AFTERLABEL-NOT: Begin completions
|
||||
}
|
||||
|
||||
struct S {
|
||||
func member() {}
|
||||
}
|
||||
func globalFunc2(x: Int = 0, _ fn: () -> Void) -> S {}
|
||||
func globalFunc3(x: Int, _ fn: () -> Void) -> S {}
|
||||
|
||||
func testNonFuncArg() {
|
||||
do {
|
||||
// Don't complete for a non-function default argument.
|
||||
globalFunc2 {} #^GLOBALFUNC2^#
|
||||
// GLOBALFUNC2: Begin completions, 2 items
|
||||
// GLOBALFUNC2-DAG: Decl[InstanceMethod]/CurrNominal: .member()[#Void#]; name=member()
|
||||
// GLOBALFUNC2-DAG: Keyword[self]/CurrNominal: .self[#S#]; name=self
|
||||
|
||||
globalFunc2 {}
|
||||
.#^GLOBALFUNC2_DOT^#
|
||||
// GLOBALFUNC2_DOT: Begin completions, 2 items
|
||||
// GLOBALFUNC2_DOT-DAG: Decl[InstanceMethod]/CurrNominal: member()[#Void#]; name=member()
|
||||
// GLOBALFUNC2_DOT-DAG: Keyword[self]/CurrNominal: self[#S#]; name=self
|
||||
}
|
||||
do {
|
||||
globalFunc3 {} #^GLOBALFUNC3^#
|
||||
// GLOBALFUNC3: Begin completions, 2 items
|
||||
// GLOBALFUNC3-DAG: Decl[InstanceMethod]/CurrNominal: .member()[#Void#]; name=member()
|
||||
// GLOBALFUNC3-DAG: Keyword[self]/CurrNominal: .self[#S#]; name=self
|
||||
|
||||
globalFunc3 {}
|
||||
.#^GLOBALFUNC3_DOT^#
|
||||
// GLOBALFUNC3_DOT: Begin completions, 2 items
|
||||
// GLOBALFUNC3_DOT-DAG: Decl[InstanceMethod]/CurrNominal: member()[#Void#]; name=member()
|
||||
// GLOBALFUNC3_DOT-DAG: Keyword[self]/CurrNominal: self[#S#]; name=self
|
||||
}
|
||||
}
|
||||
|
||||
struct SimpleEnum {
|
||||
case foo, bar
|
||||
|
||||
@@ -182,10 +216,9 @@ func testFallbackPostfix() {
|
||||
let _ = MyStruct4 {
|
||||
1
|
||||
} #^INIT_FALLBACK_1^#
|
||||
// INIT_FALLBACK_1: Begin completions, 3 items
|
||||
// INIT_FALLBACK_1: Begin completions, 2 items
|
||||
// INIT_FALLBACK_1-DAG: Keyword[self]/CurrNominal: .self[#MyStruct4<Int>#]; name=self
|
||||
// INIT_FALLBACK_1-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: .testStructMethod()[#Void#]; name=testStructMethod()
|
||||
// INIT_FALLBACK_1-DAG: Pattern/Local/Flair[ArgLabels]: {#arg1: Int#}[#Int#]; name=arg1:
|
||||
let _ = MyStruct4(name: "test") {
|
||||
""
|
||||
} arg3: {
|
||||
|
||||
Reference in New Issue
Block a user