[kernel] Disallow const x = [] and const y = {}
This CL makes fasta issue an error when trying to create a non-const ListLiteral or MapLiteral in a context where const is required. Bug: Change-Id: I27ea151a38eb1198faa83a8cfa57453a4e225e1a Reviewed-on: https://dart-review.googlesource.com/15460 Commit-Queue: Jens Johansen <jensj@google.com> Reviewed-by: Peter von der Ahé <ahe@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
e4b72146ca
commit
c8b2183bb5
@@ -1639,8 +1639,13 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
|
||||
beginToken.charOffset);
|
||||
}
|
||||
}
|
||||
bool isConst = constKeyword != null;
|
||||
if (constantExpressionRequired && !isConst) {
|
||||
deprecated_addCompileTimeError(
|
||||
offsetForToken(beginToken), "Not a constant expression.");
|
||||
}
|
||||
push(new ShadowListLiteral(expressions,
|
||||
typeArgument: typeArgument, isConst: constKeyword != null)
|
||||
typeArgument: typeArgument, isConst: isConst)
|
||||
..fileOffset = offsetForToken(constKeyword ?? beginToken));
|
||||
}
|
||||
|
||||
@@ -1684,8 +1689,15 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
|
||||
valueType = typeArguments[1];
|
||||
}
|
||||
}
|
||||
|
||||
bool isConst = constKeyword != null;
|
||||
|
||||
if (constantExpressionRequired && !isConst) {
|
||||
deprecated_addCompileTimeError(
|
||||
offsetForToken(beginToken), "Not a constant expression.");
|
||||
}
|
||||
push(new ShadowMapLiteral(entries,
|
||||
keyType: keyType, valueType: valueType, isConst: constKeyword != null)
|
||||
keyType: keyType, valueType: valueType, isConst: isConst)
|
||||
..fileOffset = constKeyword?.charOffset ?? offsetForToken(beginToken));
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,6 @@ Language/Expressions/Constants/bitwise_operators_t02: Crash
|
||||
Language/Expressions/Constants/bitwise_operators_t03: Crash
|
||||
Language/Expressions/Constants/bitwise_operators_t04: Crash
|
||||
Language/Expressions/Constants/bitwise_operators_t06: Crash
|
||||
Language/Expressions/Constants/constant_list_t02: MissingCompileTimeError
|
||||
Language/Expressions/Constants/constant_map_t02: MissingCompileTimeError
|
||||
Language/Expressions/Constants/depending_on_itself_t03: Crash
|
||||
Language/Expressions/Constants/equals_expression_t03: MissingCompileTimeError
|
||||
Language/Expressions/Constants/exception_t04: MissingCompileTimeError
|
||||
@@ -50,10 +48,8 @@ Language/Expressions/Constants/math_operators_t04: Crash
|
||||
Language/Expressions/Constants/math_operators_t05: Crash
|
||||
Language/Expressions/Function_Invocation/Unqualified_Invocation/instance_context_invocation_t03: MissingCompileTimeError
|
||||
Language/Expressions/Function_Invocation/Unqualified_Invocation/instance_context_invocation_t04: MissingCompileTimeError
|
||||
Language/Expressions/Instance_Creation/Const/arguments_t03: MissingCompileTimeError
|
||||
Language/Expressions/Instance_Creation/New/evaluation_t19: RuntimeError # Kernel Issue 28335 (deferred libraries)
|
||||
Language/Expressions/Instance_Creation/New/evaluation_t20: RuntimeError # Kernel Issue 28335 (deferred libraries)
|
||||
Language/Expressions/Maps/constant_map_t02: MissingCompileTimeError
|
||||
Language/Expressions/Maps/key_value_equals_operator_t01: MissingCompileTimeError
|
||||
Language/Expressions/Method_Invocation/Ordinary_Invocation/object_method_invocation_t01: MissingCompileTimeError # Issue 25496
|
||||
Language/Expressions/Method_Invocation/Ordinary_Invocation/object_method_invocation_t02: MissingCompileTimeError # Issue 25496
|
||||
|
||||
@@ -198,19 +198,16 @@ bool_from_environment2_test/01: MissingCompileTimeError
|
||||
bool_from_environment2_test/02: MissingCompileTimeError
|
||||
bool_from_environment2_test/03: MissingCompileTimeError
|
||||
bool_from_environment2_test/04: MissingCompileTimeError
|
||||
bool_from_environment2_test/05: MissingCompileTimeError
|
||||
compare_to2_test: RuntimeError
|
||||
int_from_environment3_test/01: MissingCompileTimeError
|
||||
int_from_environment3_test/02: MissingCompileTimeError
|
||||
int_from_environment3_test/03: MissingCompileTimeError
|
||||
int_from_environment3_test/04: MissingCompileTimeError
|
||||
int_from_environment3_test/05: MissingCompileTimeError
|
||||
string_case_test/01: RuntimeError
|
||||
string_from_environment3_test/01: MissingCompileTimeError
|
||||
string_from_environment3_test/02: MissingCompileTimeError
|
||||
string_from_environment3_test/03: MissingCompileTimeError
|
||||
string_from_environment3_test/04: MissingCompileTimeError
|
||||
string_from_environment3_test/05: MissingCompileTimeError
|
||||
string_trimlr_test/02: RuntimeError
|
||||
symbol_operator_test/03: RuntimeError
|
||||
symbol_reserved_word_test/04: MissingCompileTimeError
|
||||
|
||||
@@ -292,7 +292,6 @@ bool_from_environment2_test/01: MissingCompileTimeError
|
||||
bool_from_environment2_test/02: MissingCompileTimeError
|
||||
bool_from_environment2_test/03: MissingCompileTimeError
|
||||
bool_from_environment2_test/04: MissingCompileTimeError
|
||||
bool_from_environment2_test/05: MissingCompileTimeError
|
||||
compare_to2_test: RuntimeError
|
||||
string_trimlr_test/02: RuntimeError
|
||||
symbol_operator_test/03: RuntimeError
|
||||
@@ -312,7 +311,6 @@ string_from_environment3_test/01: MissingCompileTimeError
|
||||
string_from_environment3_test/02: MissingCompileTimeError
|
||||
string_from_environment3_test/03: MissingCompileTimeError
|
||||
string_from_environment3_test/04: MissingCompileTimeError
|
||||
string_from_environment3_test/05: MissingCompileTimeError
|
||||
|
||||
[ ($compiler == dartk || $compiler == dartkp) && ($runtime == vm || $runtime == dart_precompiled) && $mode == debug]
|
||||
list_test/*: Crash
|
||||
|
||||
Reference in New Issue
Block a user