Issue 47422. Fix crash in constant evaluation when the number of positional arguments is less the the number of required positional parameters.

Bug: https://github.com/dart-lang/sdk/issues/47422
Change-Id: I3d45b12a131c3cb4d7f08680fc906d6f33d056c2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216140
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2021-10-11 04:59:02 +00:00 committed by commit-bot@chromium.org
parent 12f7507af2
commit 9c10d2b7ff
2 changed files with 16 additions and 1 deletions

View file

@ -2206,7 +2206,7 @@ class _InstanceCreationEvaluator {
if (baseParameter.isNamed) {
argumentValue = _namedValues[baseParameter.name];
errorTarget = _namedNodes[baseParameter.name];
} else if (i < arguments.length) {
} else if (i < _argumentValues.length) {
argumentValue = _argumentValues[i];
errorTarget = arguments[i];
}

View file

@ -29,6 +29,21 @@ main() {
]);
}
test_const_namedArgument_insteadOfRequiredPositional() async {
await assertErrorsInCode(r'''
class A {
const A(int p);
}
main() {
const A(p: 0);
}
''', [
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 41, 13),
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 48, 6),
error(CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER, 49, 1),
]);
}
test_const_super() async {
await assertErrorsInCode(r'''
class A {