Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 0cdd5b9

Browse files
sigmundchcommit-bot@chromium.org
authored andcommitted
Raise warning to error: duplicate key in a const map is now an error in Dart.
Eventually the plan is to handle this in the CFE when it performs constant-evaluation, but for now we can check this in dart2js (see dart-lang/sdk#32983) Change-Id: Ic2e5cfd96961094e634da201c55f82398c060aca Reviewed-on: https://dart-review.googlesource.com/c/79421 Commit-Queue: Sigmund Cherem <[email protected]> Reviewed-by: Stephen Adams <[email protected]>
1 parent f6ca2c1 commit 0cdd5b9

File tree

4 files changed

+14
-36
lines changed

4 files changed

+14
-36
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222

2323
#### Pub
2424

25+
#### dart2js
26+
27+
* Breaking change: duplicate keys in a const map are not allowed and produce a
28+
compile-time error. Dart2js used to report this as a warning before. Note
29+
this is already an error in dartanalyzer and DDC and will be an error in
30+
other tools in the future as well.
31+
2532
#### Other Tools
2633

2734
## 2.1.0-dev.7.0

pkg/compiler/lib/src/constants/expressions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ class MapConstantExpression extends ConstantExpression {
481481
return new NonConstantValue();
482482
}
483483
if (map.containsKey(key)) {
484-
environment.reportWarning(keys[i], MessageKind.EQUAL_MAP_ENTRY_KEY, {});
484+
environment.reportError(keys[i], MessageKind.EQUAL_MAP_ENTRY_KEY, {});
485485
}
486486
map[key] = value;
487487
}

tests/language_2/language_2_dart2js.status

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ canonical_const2_test: RuntimeError, OK # non JS number semantics
161161
checked_method_error_order_test: RuntimeError
162162
class_cycle_test/02: MissingCompileTimeError
163163
class_cycle_test/03: MissingCompileTimeError
164-
compile_time_constant_o_test/01: MissingCompileTimeError
165-
compile_time_constant_o_test/02: MissingCompileTimeError
166164
conditional_method_invocation_test/05: MissingCompileTimeError
167165
conditional_method_invocation_test/06: MissingCompileTimeError
168166
conditional_method_invocation_test/07: MissingCompileTimeError
@@ -215,7 +213,6 @@ const_constructor2_test/18: MissingCompileTimeError
215213
const_constructor2_test/20: MissingCompileTimeError
216214
const_constructor2_test/22: MissingCompileTimeError
217215
const_constructor2_test/24: MissingCompileTimeError
218-
const_dynamic_type_literal_test/02: MissingCompileTimeError
219216
const_error_multiply_initialized_test/02: MissingCompileTimeError
220217
const_error_multiply_initialized_test/04: MissingCompileTimeError
221218
const_evaluation_test/01: RuntimeError
@@ -442,20 +439,11 @@ class_literal_static_test/01: MissingCompileTimeError
442439
class_literal_static_test/03: MissingCompileTimeError
443440
class_literal_static_test/07: MissingCompileTimeError
444441
closure_self_reference_test: Crash # 'file:*/pkg/compiler/lib/src/ssa/nodes.dart': Failed assertion: line 641 pos 12: 'isClosed()': is not true.
445-
compile_time_constant_k_test/01: MissingCompileTimeError
446-
compile_time_constant_k_test/02: MissingCompileTimeError
447-
compile_time_constant_k_test/03: MissingCompileTimeError
448442
config_import_corelib_test: CompileTimeError
449443
covariant_subtyping_test: RuntimeError
450-
identical_const_test/01: MissingCompileTimeError
451-
identical_const_test/02: MissingCompileTimeError
452-
identical_const_test/03: MissingCompileTimeError
453-
identical_const_test/04: MissingCompileTimeError
454444
issue23244_test: Crash # 'file:*/pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart': Failed assertion: line 208 pos 18: '!(_useKernel && _strongMode && !_disableRtiOptimization) ||
455445
library_env_test/has_no_html_support: RuntimeError
456446
library_env_test/has_no_io_support: RuntimeError
457-
map_literal3_test/01: MissingCompileTimeError
458-
map_literal3_test/02: MissingCompileTimeError
459447
map_literal3_test/03: MissingCompileTimeError
460448
partial_tearoff_instantiation_test/05: Crash # Assertion failure: kind=special,memberName=instantiate,callStructure:CallStructure(arity=0, types=1)
461449
partial_tearoff_instantiation_test/06: Crash # Assertion failure: kind=special,memberName=instantiate,callStructure:CallStructure(arity=0, types=1)
@@ -490,22 +478,13 @@ call_with_no_such_method_test: RuntimeError
490478
class_literal_static_test/01: MissingCompileTimeError
491479
class_literal_static_test/03: MissingCompileTimeError
492480
class_literal_static_test/07: MissingCompileTimeError
493-
compile_time_constant_k_test/01: MissingCompileTimeError
494-
compile_time_constant_k_test/02: MissingCompileTimeError
495-
compile_time_constant_k_test/03: MissingCompileTimeError
496481
config_import_corelib_test: CompileTimeError
497482
covariant_subtyping_test: RuntimeError
498-
identical_const_test/01: MissingCompileTimeError
499-
identical_const_test/02: MissingCompileTimeError
500-
identical_const_test/03: MissingCompileTimeError
501-
identical_const_test/04: MissingCompileTimeError
502483
invocation_mirror2_test: RuntimeError # mirrors not supported
503484
invocation_mirror_test: RuntimeError
504485
issue23244_test: Crash # Interpolated value #1 is not an Expression or List of Expressions: [VariableUse(f), Instance of 'LiteralNull', null]
505486
library_env_test/has_no_html_support: RuntimeError
506487
many_overridden_no_such_method_test: RuntimeError
507-
map_literal3_test/01: MissingCompileTimeError
508-
map_literal3_test/02: MissingCompileTimeError
509488
map_literal3_test/03: MissingCompileTimeError
510489
mixin_generic_test: RuntimeError # Issue 12605
511490
mixin_mixin_type_arguments_test: RuntimeError
@@ -530,16 +509,13 @@ bit_operations_test: RuntimeError
530509
branch_canonicalization_test: RuntimeError
531510
canonical_const2_test: RuntimeError, OK # non JS number semantics
532511
closure_type_arguments_test: Crash # Issue 34272
533-
compile_time_constant_o_test/01: MissingCompileTimeError
534-
compile_time_constant_o_test/02: MissingCompileTimeError
535512
compile_time_constant_static5_test/11: CompileTimeError
536513
compile_time_constant_static5_test/16: CompileTimeError
537514
compile_time_constant_static5_test/21: CompileTimeError
538515
compile_time_constant_static5_test/23: CompileTimeError
539516
conditional_rewrite_test: RuntimeError
540517
config_import_test: RuntimeError
541518
const_constructor3_test/04: MissingCompileTimeError # OK - Subtype check uses JS number semantics.
542-
const_dynamic_type_literal_test/02: MissingCompileTimeError
543519
const_evaluation_test/01: RuntimeError
544520
const_list_test: RuntimeError
545521
const_map2_test/00: MissingCompileTimeError

tests/language_2/language_2_kernel.status

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -263,19 +263,11 @@ const_optional_args_test/01: MissingCompileTimeError
263263
# compile-time errors).
264264
[ $compiler != dart2analyzer && $compiler != dart2js && $compiler != dartkb && $compiler != dartkp && $fasta ]
265265
compile_time_constant_c_test/02: MissingCompileTimeError
266-
const_constructor_nonconst_field_test/01: MissingCompileTimeError
267-
const_syntax_test/05: MissingCompileTimeError
268-
269-
[ $compiler != dart2analyzer && $compiler != dart2js && $fasta && $strong ]
270-
super_call4_test/01: MissingCompileTimeError
271-
272-
# The precomilation and bytecode configurations use a kernel2kernel constants evaluator
273-
# which is is more correct than fasta/vm in JIT mode (i.e. it catches more
274-
# compile-time errors).
275-
[ $compiler != dart2analyzer && $compiler != dartkb && $compiler != dartkp && $fasta ]
276266
compile_time_constant_o_test/01: MissingCompileTimeError # Issue 32983
277267
compile_time_constant_o_test/02: MissingCompileTimeError # Issue 32983
268+
const_constructor_nonconst_field_test/01: MissingCompileTimeError
278269
const_dynamic_type_literal_test/02: MissingCompileTimeError # Issue 32983
270+
const_syntax_test/05: MissingCompileTimeError
279271
identical_const_test/01: MissingCompileTimeError # Issue 32983
280272
identical_const_test/02: MissingCompileTimeError # Issue 32983
281273
identical_const_test/03: MissingCompileTimeError # Issue 32983
@@ -284,13 +276,16 @@ identical_const_test/04: MissingCompileTimeError # Issue 32983
284276
# The precomilation and bytecode configurations use a kernel2kernel constants evaluator
285277
# which is is more correct than fasta/vm in JIT mode (i.e. it catches more
286278
# compile-time errors).
287-
[ $compiler != dart2analyzer && $compiler != dartkb && $compiler != dartkp && $fasta && $strong ]
279+
[ $compiler != dart2analyzer && $compiler != dart2js && $compiler != dartkb && $compiler != dartkp && $fasta && $strong ]
288280
compile_time_constant_k_test/01: MissingCompileTimeError
289281
compile_time_constant_k_test/02: MissingCompileTimeError
290282
compile_time_constant_k_test/03: MissingCompileTimeError
291283
map_literal3_test/01: MissingCompileTimeError
292284
map_literal3_test/02: MissingCompileTimeError
293285

286+
[ $compiler != dart2analyzer && $compiler != dart2js && $fasta && $strong ]
287+
super_call4_test/01: MissingCompileTimeError
288+
294289
[ $compiler != dart2analyzer && $fasta ]
295290
const_map2_test/00: MissingCompileTimeError # KernelVM bug: Constant evaluation.
296291
const_map3_test/00: MissingCompileTimeError # KernelVM bug: Constant evaluation.

0 commit comments

Comments
 (0)