Skip to content

Commit 9c10d2b

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Issue 47422. Fix crash in constant evaluation when the number of positional arguments is less the the number of required positional parameters.
Bug: #47422 Change-Id: I3d45b12a131c3cb4d7f08680fc906d6f33d056c2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216140 Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 12f7507 commit 9c10d2b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pkg/analyzer/lib/src/dart/constant/evaluation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,7 @@ class _InstanceCreationEvaluator {
22062206
if (baseParameter.isNamed) {
22072207
argumentValue = _namedValues[baseParameter.name];
22082208
errorTarget = _namedNodes[baseParameter.name];
2209-
} else if (i < arguments.length) {
2209+
} else if (i < _argumentValues.length) {
22102210
argumentValue = _argumentValues[i];
22112211
errorTarget = arguments[i];
22122212
}

pkg/analyzer/test/src/diagnostics/not_enough_positional_arguments_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ main() {
2929
]);
3030
}
3131

32+
test_const_namedArgument_insteadOfRequiredPositional() async {
33+
await assertErrorsInCode(r'''
34+
class A {
35+
const A(int p);
36+
}
37+
main() {
38+
const A(p: 0);
39+
}
40+
''', [
41+
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, 41, 13),
42+
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 48, 6),
43+
error(CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER, 49, 1),
44+
]);
45+
}
46+
3247
test_const_super() async {
3348
await assertErrorsInCode(r'''
3449
class A {

0 commit comments

Comments
 (0)