Completion. Issue 40588. Support for function typed functions invoked.

Bug: https://github.com/dart-lang/sdk/issues/40588
Change-Id: Ifc4ff940e5a519dab982f5ab771fe95277c3ae94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356480
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2024-03-09 00:26:17 +00:00 committed by Commit Queue
parent f30da31b21
commit da488fdb78
2 changed files with 36 additions and 15 deletions

View file

@ -229,8 +229,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
var (:positionalArgumentCount, :usedNames) =
node.argumentContext(argumentIndex);
var element = node.invokedElement;
var parameters = element.getParameters();
var parameters = node.invokedFormalParameters;
if (parameters != null) {
var positionalParameterCount = 0;
var availableNamedParameters = <ParameterElement>[];
@ -1542,14 +1541,14 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
if (argumentList is! ArgumentList) {
return;
}
var element = argumentList.invokedElement;
if (element is ExecutableElement) {
var parameters = argumentList.invokedFormalParameters;
if (parameters != null) {
var (positionalArgumentCount: _, :usedNames) =
argumentList.argumentContext(-1);
usedNames.remove(node.name.label.name);
var appendColon = node.name.colon.isSynthetic;
var parameters = element.parameters;
for (int i = 0; i < parameters.length; i++) {
var parameter = parameters[i];
if (parameter.isNamed) {
@ -3052,6 +3051,23 @@ extension on ArgumentList {
return null;
}
List<ParameterElement>? get invokedFormalParameters {
var result = invokedElement?.getParameters();
if (result != null) {
return result;
}
switch (parent) {
case FunctionExpressionInvocation invocation:
var functionType = invocation.function.staticType;
if (functionType is FunctionType) {
return functionType.parameters;
}
}
return null;
}
/// Returns a record whose fields indicate the number of positional arguments
/// before the argument at the [argumentIndex], and the names of named
/// parameters that are already in use.

View file

@ -930,20 +930,25 @@ var v = f$arguments;
await computeAndCheck('''
$languageVersionLine
class A {
A$parameters;
void foo(void Function$parameters f) {
f$arguments;
}
class B extends A {
B() : super$arguments;
}
''', ' (super constructor invocation)');
''', ' (invocation, function typed formal parameter)');
await computeAndCheck('''
$languageVersionLine
class A {
A$parameters;
A.named() : this$arguments;
void foo() {
void Function$parameters f; // not initialized
f$arguments;
}
''', ' (this constructor invocation)');
''', ' (invocation, function typed local variable)');
await computeAndCheck('''
$languageVersionLine
void Function$parameters foo() => throw 0;
void f() {
foo()$arguments;
}
''', ' (invocation, function typed expression)');
}
}