cdf7bf9c78
This relies on runtime check of Map-typed variable initialization. TEST=kernel_binary_flowgraph_test Change-Id: Ia9be2644208883739f5896a223dcbe2b59c98114 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/482021 Reviewed-by: Slava Egorov <vegorov@google.com>
35 lines
939 B
Dart
35 lines
939 B
Dart
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import "dart:_compact_hash" show createConstMapFromMapOfDeeplyImmutables;
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
@pragma('vm:deeply-immutable')
|
|
final class Foo {
|
|
final Map<String, Object> bar;
|
|
|
|
Foo(this.bar);
|
|
}
|
|
|
|
main() {
|
|
final foo = Foo(const {"abc": "def"});
|
|
Expect.equals(1, foo.bar.length);
|
|
|
|
Expect.throws(() => Foo({"abc": "def"}), (e) => e is ArgumentError);
|
|
|
|
final foo1 = Foo(createConstMapFromMapOfDeeplyImmutables({"abc": "def"}));
|
|
Expect.equals(1, foo1.bar.length);
|
|
|
|
Expect.throws(
|
|
() => Foo({"ghi": foo, "jkl": foo1}),
|
|
(e) => e is ArgumentError,
|
|
);
|
|
|
|
final foo2 = Foo(
|
|
createConstMapFromMapOfDeeplyImmutables({"ghi": foo, "jkl": foo1}),
|
|
);
|
|
Expect.equals(2, foo2.bar.length);
|
|
}
|