Skip to content

Commit

Permalink
Issue 47422. Fix crash in constant evaluation when the number of posi…
Browse files Browse the repository at this point in the history
…tional arguments is less the the number of required positional parameters.

Bug: dart-lang#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>
  • Loading branch information
scheglov authored and commit-bot@chromium.org committed Oct 11, 2021
1 parent 12f7507 commit 9c10d2b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/constant/evaluation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9c10d2b

Please sign in to comment.