Fix context type when recovering from "too many positional parameters".

See discussion at
https://dart-review.googlesource.com/c/sdk/+/234864/comments/0512a739_f86ad5be.

Change-Id: I201dcd9d8eca07d14579d00d76e08fe824d9d1e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/235560
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
Paul Berry 2022-03-06 22:54:22 +00:00 committed by Commit Bot
parent 5f0afa0ac4
commit 4f5d82d312
2 changed files with 20 additions and 2 deletions

View file

@ -388,8 +388,9 @@ abstract class InvocationInferrer<Node extends AstNodeImpl> {
parameter = namedParameters[argument.name.label.name];
} else if (parameters != null) {
while (positionalParameterIndex < parameters.length) {
parameter = parameters[positionalParameterIndex++];
if (!parameter.isNamed) {
var candidate = parameters[positionalParameterIndex++];
if (!candidate.isNamed) {
parameter = candidate;
break;
}
}

View file

@ -60,6 +60,23 @@ main() {
]);
}
test_context() async {
// No context type should be supplied when type inferring an extra
// positional argument, even if there is an unmatched name parameter.
await assertErrorsInCode(r'''
T f<T>() => throw '$T';
g({int? named}) {}
main() {
g(f());
}
''', [
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED, 56,
3),
]);
assertType(
findNode.methodInvocation('f()').typeArgumentTypes!.single, 'dynamic');
}
test_enumConstant() async {
await assertErrorsInCode(r'''
enum E {