mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
Handle NON_CONSTANT_MAP_ELEMENT as a const error.
Bug: https://dart-review.googlesource.com/c/sdk/+/191762 Change-Id: I55c52a364079fbf797b285c48bb7eed070c00b9e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191803 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
e692b26c7e
commit
14327ea035
2 changed files with 46 additions and 0 deletions
|
@ -849,6 +849,7 @@ class _ConstantAnalysisErrorListener extends AnalysisErrorListener {
|
|||
case CompileTimeErrorCode.MISSING_CONST_IN_MAP_LITERAL:
|
||||
case CompileTimeErrorCode.MISSING_CONST_IN_SET_LITERAL:
|
||||
case CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT:
|
||||
case CompileTimeErrorCode.NON_CONSTANT_MAP_ELEMENT:
|
||||
case CompileTimeErrorCode.NON_CONSTANT_MAP_KEY:
|
||||
case CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE:
|
||||
case CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT:
|
||||
|
|
|
@ -311,6 +311,13 @@ class CanBeConstTypedLiteralTest extends AbstractLinterContextTest {
|
|||
expect(context.canBeConst(node), expectedResult);
|
||||
}
|
||||
|
||||
void test_listLiteral_false_forElement() async {
|
||||
await resolve('''
|
||||
f() => [for (var i = 0; i < 10; i++) i];
|
||||
''');
|
||||
assertCanBeConst('[for', false);
|
||||
}
|
||||
|
||||
void test_listLiteral_false_methodInvocation() async {
|
||||
await resolve('''
|
||||
f() => [g()];
|
||||
|
@ -354,6 +361,14 @@ f() => [A()];
|
|||
assertCanBeConst('[', true);
|
||||
}
|
||||
|
||||
void test_listLiteral_true_ifElement() async {
|
||||
await resolve('''
|
||||
const a = true;
|
||||
f() => [if (a) 0 else 1];
|
||||
''');
|
||||
assertCanBeConst('[if', true);
|
||||
}
|
||||
|
||||
void test_listLiteral_true_integerLiteral() async {
|
||||
await resolve('''
|
||||
f() => [1, 2, 3];
|
||||
|
@ -361,6 +376,13 @@ f() => [1, 2, 3];
|
|||
assertCanBeConst('[', true);
|
||||
}
|
||||
|
||||
void test_mapLiteral_false_forElement() async {
|
||||
await resolve('''
|
||||
f() => {for (var i = 0; i < 10; i++) i: 0};
|
||||
''');
|
||||
assertCanBeConst('{', false);
|
||||
}
|
||||
|
||||
void test_mapLiteral_false_methodInvocation_key() async {
|
||||
await resolve('''
|
||||
f() => {g(): 0};
|
||||
|
@ -377,6 +399,14 @@ int g() => 0;
|
|||
assertCanBeConst('{', false);
|
||||
}
|
||||
|
||||
void test_mapLiteral_true_ifElement() async {
|
||||
await resolve('''
|
||||
const a = true;
|
||||
f() => {if (a) 0: 0 else 1: 1};
|
||||
''');
|
||||
assertCanBeConst('{', true);
|
||||
}
|
||||
|
||||
void test_mapLiteral_true_integerLiteral() async {
|
||||
await resolve('''
|
||||
f() => {1: 2, 3: 4};
|
||||
|
@ -384,6 +414,13 @@ f() => {1: 2, 3: 4};
|
|||
assertCanBeConst('{', true);
|
||||
}
|
||||
|
||||
void test_setLiteral_false_forElement() async {
|
||||
await resolve('''
|
||||
f() => {for (var i = 0; i < 10; i++) i};
|
||||
''');
|
||||
assertCanBeConst('{for', false);
|
||||
}
|
||||
|
||||
void test_setLiteral_false_methodInvocation() async {
|
||||
await resolve('''
|
||||
f() => {g()};
|
||||
|
@ -392,6 +429,14 @@ int g() => 0;
|
|||
assertCanBeConst('{', false);
|
||||
}
|
||||
|
||||
void test_setLiteral_true_ifElement() async {
|
||||
await resolve('''
|
||||
const a = true;
|
||||
f() => {if (a) 0 else 1};
|
||||
''');
|
||||
assertCanBeConst('{', true);
|
||||
}
|
||||
|
||||
void test_setLiteral_true_integerLiteral() async {
|
||||
await resolve('''
|
||||
f() => {1, 2, 3};
|
||||
|
|
Loading…
Reference in a new issue