Files
sdk/tests/lib/isolate/deeply_immutable_cfe_2_test.dart
Alexander Aprelev eb75c53d95 [vm/shared] Perform deeply-immutable initialization runtime check.
When an initial value is assigned into a class tagged as deeply-immutable, perform runtime check of that value. This is needed to support proper initialization of the closures as part of deeply-immutable classes.

BUG=https://github.com/dart-lang/sdk/issues/61962
TEST=run_isolate_group_run_test

Change-Id: I550746c0d22ca06ffb89959e8384cc9e6d28d590
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/468200
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2026-01-14 08:42:22 -08:00

37 lines
848 B
Dart

// Copyright (c) 2025, 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:async';
import 'dart:ffi';
import 'dart:isolate';
class Base {
var myMutableField;
}
@pragma('vm:deeply-immutable')
final class Foo extends Base {}
// ^^^
// [cfe] The super type of deeply immutable classes must be deeply immutable.
Future<T> sendReceive<T>(T o) async {
final r = ReceivePort();
final si = StreamIterator(r);
r.sendPort.send(o);
await si.moveNext();
final o2 = si.current;
si.cancel();
return o2;
}
main() async {
final o = Foo();
final o2 = await sendReceive(o);
if (!identical(o, o2)) throw 'not identical';
throw 'we could share mutable objects - oh no!';
}