diff --git a/tests/hot_reload/change_instance_format0/main.0.dart b/tests/hot_reload/change_instance_format0/main.0.dart new file mode 100644 index 00000000000..c1dd9868662 --- /dev/null +++ b/tests/hot_reload/change_instance_format0/main.0.dart @@ -0,0 +1,30 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L3806 + +// Tests reload succeeds when instance format changes. +// Change: Foo {a, b, c:42} -> Foo {c:42} +// Validate: c keeps the value in the retained Foo object. + +class Foo { + var a; + var b; + var c; +} + +var f; + +Future main() async { + f = Foo(); + f.c = 42; + Expect.equals(42, f.c); + await hotReload(); + + Expect.equals(42, f.c); +} diff --git a/tests/hot_reload/change_instance_format0/main.1.dart b/tests/hot_reload/change_instance_format0/main.1.dart new file mode 100644 index 00000000000..44d16bf4737 --- /dev/null +++ b/tests/hot_reload/change_instance_format0/main.1.dart @@ -0,0 +1,40 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L3806 + +// Tests reload succeeds when instance format changes. +// Change: Foo {a, b, c:42} -> Foo {c:42} +// Validate: c keeps the value in the retained Foo object. + +class Foo { + var c; +} + +var f; + +Future main() async { + f = Foo(); + f.c = 42; + Expect.equals(42, f.c); + await hotReload(); + + Expect.equals(42, f.c); +} + +/** DIFF **/ +/* + // Validate: c keeps the value in the retained Foo object. + + class Foo { +- var a; +- var b; + var c; + } + +*/ diff --git a/tests/hot_reload/change_instance_format1/main.0.dart b/tests/hot_reload/change_instance_format1/main.0.dart new file mode 100644 index 00000000000..4325717e4aa --- /dev/null +++ b/tests/hot_reload/change_instance_format1/main.0.dart @@ -0,0 +1,24 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L3841 + +// Tests reload succeeds when instance format changes. +// Change: Foo {} -> Foo {c:null} +// Validate: c is initialized to null the retained Foo object. + +class Foo {} + +var f; + +Future main() async { + f = Foo(); + await hotReload(); + + Expect.isNull(f.c); +} diff --git a/tests/hot_reload/change_instance_format1/main.1.dart b/tests/hot_reload/change_instance_format1/main.1.dart new file mode 100644 index 00000000000..30ffbba501c --- /dev/null +++ b/tests/hot_reload/change_instance_format1/main.1.dart @@ -0,0 +1,40 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L3841 + +// Tests reload succeeds when instance format changes. +// Change: Foo {} -> Foo {c:null} +// Validate: c is initialized to null the retained Foo object. + +class Foo { + var c; +} + +var f; + +Future main() async { + f = Foo(); + await hotReload(); + + Expect.isNull(f.c); +} + +/** DIFF **/ +/* + // Change: Foo {} -> Foo {c:null} + // Validate: c is initialized to null the retained Foo object. + +-class Foo {} ++class Foo { ++ var c; ++} + + var f; + +*/ diff --git a/tests/hot_reload/change_instance_format2/main.0.dart b/tests/hot_reload/change_instance_format2/main.0.dart new file mode 100644 index 00000000000..a974d9a2f55 --- /dev/null +++ b/tests/hot_reload/change_instance_format2/main.0.dart @@ -0,0 +1,28 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L3872 + +// Tests reload succeeds when instance format changes. +// Change: Foo {c:42} -> Foo {} +// Validate: running the after script fails. + +class Foo { + var c; +} + +var f; + +Future main() async { + f = Foo(); + f.c = 42; + Expect.equals(42, f.c); + await hotReload(); + + Expect.throws(() => f.c); +} diff --git a/tests/hot_reload/change_instance_format2/main.1.dart b/tests/hot_reload/change_instance_format2/main.1.dart new file mode 100644 index 00000000000..2f3f4076757 --- /dev/null +++ b/tests/hot_reload/change_instance_format2/main.1.dart @@ -0,0 +1,40 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L3872 + +// Tests reload succeeds when instance format changes. +// Change: Foo {c:42} -> Foo {} +// Validate: running the after script fails. + +class Foo {} + +var f; + +Future main() async { + f = Foo(); + f.c = 42; + Expect.equals(42, f.c); + await hotReload(); + + Expect.throws(() => f.c); +} + +/** DIFF **/ +/* + // Change: Foo {c:42} -> Foo {} + // Validate: running the after script fails. + +-class Foo { +- var c; +-} ++class Foo {} + + var f; + +*/ diff --git a/tests/hot_reload/change_instance_format3/main.0.dart b/tests/hot_reload/change_instance_format3/main.0.dart new file mode 100644 index 00000000000..271866f3ba7 --- /dev/null +++ b/tests/hot_reload/change_instance_format3/main.0.dart @@ -0,0 +1,38 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L3908 + +// Tests reload succeeds when instance format changes. +// Change: Foo {a, b, c:42, d} -> Foo {c:42, g} +// Validate: c keeps the value in the retained Foo object. + +class Foo { + var a; + var b; + var c; + var d; +} + +helper() { + f = Foo(); + f.a = 1; + f.b = 2; + f.c = 3; + f.d = 4; +} + +var f; + +Future main() async { + helper(); + Expect.equals(3, f.c); + await hotReload(); + + Expect.equals(3, f.c); +} diff --git a/tests/hot_reload/change_instance_format3/main.1.dart b/tests/hot_reload/change_instance_format3/main.1.dart new file mode 100644 index 00000000000..c36d20bef01 --- /dev/null +++ b/tests/hot_reload/change_instance_format3/main.1.dart @@ -0,0 +1,55 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L3908 + +// Tests reload succeeds when instance format changes. +// Change: Foo {a, b, c:42, d} -> Foo {c:42, g} +// Validate: c keeps the value in the retained Foo object. + +class Foo { + var c; + var g; +} + +helper() {} + +var f; + +Future main() async { + helper(); + Expect.equals(3, f.c); + await hotReload(); + + Expect.equals(3, f.c); +} + +/** DIFF **/ +/* + // Validate: c keeps the value in the retained Foo object. + + class Foo { +- var a; +- var b; + var c; +- var d; ++ var g; + } + +-helper() { +- f = Foo(); +- f.a = 1; +- f.b = 2; +- f.c = 3; +- f.d = 4; +-} ++helper() {} + + var f; + +*/ diff --git a/tests/hot_reload/change_instance_format4/main.0.dart b/tests/hot_reload/change_instance_format4/main.0.dart new file mode 100644 index 00000000000..16875506ed8 --- /dev/null +++ b/tests/hot_reload/change_instance_format4/main.0.dart @@ -0,0 +1,33 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L3948 + +// Tests reload succeeds when instance format changes. +// Change: Bar {c:42}, Foo : Bar {d, e} -> Foo {c:42} +// Validate: c keeps the value in the retained Foo object. + +class Bar { + var c; +} + +class Foo extends Bar { + var d; + var e; +} + +var f; + +Future main() async { + f = Foo(); + f.c = 42; + Expect.equals(42, f.c); + await hotReload(); + + Expect.equals(42, f.c); +} diff --git a/tests/hot_reload/change_instance_format4/main.1.dart b/tests/hot_reload/change_instance_format4/main.1.dart new file mode 100644 index 00000000000..753c8cf6d87 --- /dev/null +++ b/tests/hot_reload/change_instance_format4/main.1.dart @@ -0,0 +1,48 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L3948 + +// Tests reload succeeds when instance format changes. +// Change: Bar {c:42}, Foo : Bar {d, e} -> Foo {c:42} +// Validate: c keeps the value in the retained Foo object. + +class Foo { + var c; +} + +var f; + +Future main() async { + f = Foo(); + f.c = 42; + Expect.equals(42, f.c); + await hotReload(); + + Expect.equals(42, f.c); +} + +/** DIFF **/ +/* + // Change: Bar {c:42}, Foo : Bar {d, e} -> Foo {c:42} + // Validate: c keeps the value in the retained Foo object. + +-class Bar { ++class Foo { + var c; + } + +-class Foo extends Bar { +- var d; +- var e; +-} +- + var f; + + Future main() async { +*/ diff --git a/tests/hot_reload/change_instance_format5/main.0.dart b/tests/hot_reload/change_instance_format5/main.0.dart new file mode 100644 index 00000000000..0d5c32d26c4 --- /dev/null +++ b/tests/hot_reload/change_instance_format5/main.0.dart @@ -0,0 +1,33 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L3985 + +// Tests reload succeeds when instance format changes. +// Change: Bar {a, b}, Foo : Bar {c:42} -> Bar {c:42}, Foo : Bar {} +// Validate: c keeps the value in the retained Foo object. + +class Bar { + var a; + var b; +} + +class Foo extends Bar { + var c; +} + +var f; + +Future main() async { + f = Foo(); + f.c = 42; + Expect.equals(42, f.c); + await hotReload(); + + Expect.equals(42, f.c); +} diff --git a/tests/hot_reload/change_instance_format5/main.1.dart b/tests/hot_reload/change_instance_format5/main.1.dart new file mode 100644 index 00000000000..69bc79ee254 --- /dev/null +++ b/tests/hot_reload/change_instance_format5/main.1.dart @@ -0,0 +1,50 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L3985 + +// Tests reload succeeds when instance format changes. +// Change: Bar {a, b}, Foo : Bar {c:42} -> Bar {c:42}, Foo : Bar {} +// Validate: c keeps the value in the retained Foo object. + +class Bar { + var c; +} + +class Foo extends Bar {} + +var f; + +Future main() async { + f = Foo(); + f.c = 42; + Expect.equals(42, f.c); + await hotReload(); + + Expect.equals(42, f.c); +} + +/** DIFF **/ +/* + // Validate: c keeps the value in the retained Foo object. + + class Bar { +- var a; +- var b; +-} +- +-class Foo extends Bar { + var c; + } + ++class Foo extends Bar {} ++ + var f; + + Future main() async { +*/ diff --git a/tests/hot_reload/change_instance_format6/config.json b/tests/hot_reload/change_instance_format6/config.json new file mode 100644 index 00000000000..a56eae84069 --- /dev/null +++ b/tests/hot_reload/change_instance_format6/config.json @@ -0,0 +1,6 @@ +{ + "expectedErrors": { + "1": "type parameters have changed" + } +} + diff --git a/tests/hot_reload/change_instance_format6/main.0.dart b/tests/hot_reload/change_instance_format6/main.0.dart new file mode 100644 index 00000000000..724899077c9 --- /dev/null +++ b/tests/hot_reload/change_instance_format6/main.0.dart @@ -0,0 +1,25 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L4024 + +// Tests reload fails when type parameters change. +// Change: Foo {a, b} -> Foo {a} +// Validate: the right error message is returned. + +class Foo { + var a; + var b; +} + +Future main() async { + Foo(); + await hotReload(expectRejection: true); + + Foo(); +} diff --git a/tests/hot_reload/change_instance_format6/main.1.reject.dart b/tests/hot_reload/change_instance_format6/main.1.reject.dart new file mode 100644 index 00000000000..07033e84025 --- /dev/null +++ b/tests/hot_reload/change_instance_format6/main.1.reject.dart @@ -0,0 +1,38 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L4024 + +// Tests reload fails when type parameters change. +// Change: Foo {a, b} -> Foo {a} +// Validate: the right error message is returned. + +class Foo { + var a; +} + +Future main() async { + Foo(); + await hotReload(expectRejection: true); + + Foo(); +} + +/** DIFF **/ +/* + // Change: Foo {a, b} -> Foo {a} + // Validate: the right error message is returned. + +-class Foo { ++class Foo { + var a; +- var b; + } + + Future main() async { +*/ diff --git a/tests/hot_reload/change_instance_format7/main.0.dart b/tests/hot_reload/change_instance_format7/main.0.dart new file mode 100644 index 00000000000..c587070f201 --- /dev/null +++ b/tests/hot_reload/change_instance_format7/main.0.dart @@ -0,0 +1,23 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L4051 + +// Tests reload succeeds when type parameters are changed for allocated class. +// Change: Foo {a, b} -> Foo {a} +// Validate: return value from main is correct. +// Please note: This test works because no instances are created from Foo. + +class Foo { + var a; + var b; +} + +Future main() async { + await hotReload(); +} diff --git a/tests/hot_reload/change_instance_format7/main.1.dart b/tests/hot_reload/change_instance_format7/main.1.dart new file mode 100644 index 00000000000..582b689bc62 --- /dev/null +++ b/tests/hot_reload/change_instance_format7/main.1.dart @@ -0,0 +1,36 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L4051 + +// Tests reload succeeds when type parameters are changed for allocated class. +// Change: Foo {a, b} -> Foo {a} +// Validate: return value from main is correct. +// Please note: This test works because no instances are created from Foo. + +class Foo { + var a; +} + +Future main() async { + await hotReload(); +} + +/** DIFF **/ +/* + // Validate: return value from main is correct. + // Please note: This test works because no instances are created from Foo. + +-class Foo { ++class Foo { + var a; +- var b; + } + + Future main() async { +*/ diff --git a/tests/hot_reload/change_instance_format8/main.0.dart b/tests/hot_reload/change_instance_format8/main.0.dart new file mode 100644 index 00000000000..73ac978a4ca --- /dev/null +++ b/tests/hot_reload/change_instance_format8/main.0.dart @@ -0,0 +1,33 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L4071 + +// Regression for handle sharing bug: Change the shape of two classes and see +// that their instances don't change class. + +class A { + var x; +} + +class B { + var x, y, z, w; +} + +var a, b; + +Future main() async { + a = A(); + b = B(); + Expect.type(a); + Expect.type(b); + await hotReload(); + + Expect.type(a); + Expect.type(b); +} diff --git a/tests/hot_reload/change_instance_format8/main.1.dart b/tests/hot_reload/change_instance_format8/main.1.dart new file mode 100644 index 00000000000..0f7d6555db7 --- /dev/null +++ b/tests/hot_reload/change_instance_format8/main.1.dart @@ -0,0 +1,50 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L4071 + +// Regression for handle sharing bug: Change the shape of two classes and see +// that their instances don't change class. + +class A { + var x, y; +} + +class B { + var x, y, z, w, v; +} + +var a, b; + +Future main() async { + a = A(); + b = B(); + Expect.type(a); + Expect.type(b); + await hotReload(); + + Expect.type(a); + Expect.type(b); +} + +/** DIFF **/ +/* + // that their instances don't change class. + + class A { +- var x; ++ var x, y; + } + + class B { +- var x, y, z, w; ++ var x, y, z, w, v; + } + + var a, b; +*/ diff --git a/tests/hot_reload/change_instance_format9/config.json b/tests/hot_reload/change_instance_format9/config.json new file mode 100644 index 00000000000..a56eae84069 --- /dev/null +++ b/tests/hot_reload/change_instance_format9/config.json @@ -0,0 +1,6 @@ +{ + "expectedErrors": { + "1": "type parameters have changed" + } +} + diff --git a/tests/hot_reload/change_instance_format9/main.0.dart b/tests/hot_reload/change_instance_format9/main.0.dart new file mode 100644 index 00000000000..a0cf282c3e8 --- /dev/null +++ b/tests/hot_reload/change_instance_format9/main.0.dart @@ -0,0 +1,28 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L4110 + +// Tests reload fails when type arguments change. +// Change: Baz extends Foo -> Baz extends Bar +// Validate: the right error message is returned. + +class Foo { + var a; +} + +class Bar extends Foo {} + +class Baz extends Foo {} + +Future main() async { + Baz(); + await hotReload(expectRejection: true); + + Baz(); +} diff --git a/tests/hot_reload/change_instance_format9/main.1.reject.dart b/tests/hot_reload/change_instance_format9/main.1.reject.dart new file mode 100644 index 00000000000..cf8b5eca011 --- /dev/null +++ b/tests/hot_reload/change_instance_format9/main.1.reject.dart @@ -0,0 +1,40 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L4110 + +// Tests reload fails when type arguments change. +// Change: Baz extends Foo -> Baz extends Bar +// Validate: the right error message is returned. + +class Foo { + var a; +} + +class Bar extends Foo {} + +class Baz extends Bar {} + +Future main() async { + Baz(); + await hotReload(expectRejection: true); + + Baz(); +} + +/** DIFF **/ +/* + + class Bar extends Foo {} + +-class Baz extends Foo {} ++class Baz extends Bar {} + + Future main() async { + Baz(); +*/ diff --git a/tests/hot_reload/complex_inheritance_change/main.0.dart b/tests/hot_reload/complex_inheritance_change/main.0.dart new file mode 100644 index 00000000000..2ff7acbc7b3 --- /dev/null +++ b/tests/hot_reload/complex_inheritance_change/main.0.dart @@ -0,0 +1,51 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L959 + +class A { + String name; + A(this.name); +} + +class B extends A { + B(name) : super(name); +} + +class C extends B { + C(name) : super(name); +} + +helper() {} + +var list = [A('a'), B('b'), C('c')]; + +check() { + Expect.type(list[0]); + Expect.notType(list[0]); + Expect.notType(list[0]); + Expect.type(list[1]); + Expect.type(list[1]); + Expect.notType(list[1]); + Expect.type(list[2]); + Expect.type(list[2]); + Expect.type(list[2]); +} + +Future main() async { + check(); + await hotReload(); + + helper(); + check(); + await hotReload(); + + // Revive the class B and make sure all allocated instances take + // their place in the inheritance hierarchy. + check(); +} diff --git a/tests/hot_reload/complex_inheritance_change/main.1.dart b/tests/hot_reload/complex_inheritance_change/main.1.dart new file mode 100644 index 00000000000..27ee10f10c9 --- /dev/null +++ b/tests/hot_reload/complex_inheritance_change/main.1.dart @@ -0,0 +1,112 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L959 + +class C { + String name; + C(this.name); +} + +class X extends C { + X(name) : super(name); +} + +class A extends X { + A(name) : super(name); +} + +helper() { + list.add(new X('x')); +} + +var list; + +check() { + Expect.type(list[0]); + Expect.type(list[0]); + Expect.type(list[0]); + Expect.type(list[1]); + Expect.type(list[1]); + Expect.type(list[1]); + Expect.notType(list[2]); + Expect.type(list[2]); + Expect.notType(list[2]); + Expect.notType(list[3]); + Expect.type(list[3]); + Expect.type(list[3]); +} + +Future main() async { + check(); + await hotReload(); + + helper(); + check(); + await hotReload(); + + // Revive the class B and make sure all allocated instances take + // their place in the inheritance hierarchy. + check(); +} + +/** DIFF **/ +/* + // Adapted from: + // https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L959 + +-class A { ++class C { + String name; +- A(this.name); ++ C(this.name); + } + +-class B extends A { +- B(name) : super(name); ++class X extends C { ++ X(name) : super(name); + } + +-class C extends B { +- C(name) : super(name); ++class A extends X { ++ A(name) : super(name); + } + +-helper() {} ++helper() { ++ list.add(new X('x')); ++} + +-var list = [A('a'), B('b'), C('c')]; ++var list; + + check() { + Expect.type(list[0]); +- Expect.notType(list[0]); +- Expect.notType(list[0]); ++ Expect.type(list[0]); ++ Expect.type(list[0]); + Expect.type(list[1]); +- Expect.type(list[1]); +- Expect.notType(list[1]); +- Expect.type(list[2]); +- Expect.type(list[2]); ++ Expect.type(list[1]); ++ Expect.type(list[1]); ++ Expect.notType(list[2]); + Expect.type(list[2]); ++ Expect.notType(list[2]); ++ Expect.notType(list[3]); ++ Expect.type(list[3]); ++ Expect.type(list[3]); + } + + Future main() async { +*/ diff --git a/tests/hot_reload/complex_inheritance_change/main.2.dart b/tests/hot_reload/complex_inheritance_change/main.2.dart new file mode 100644 index 00000000000..5ac4c8cc852 --- /dev/null +++ b/tests/hot_reload/complex_inheritance_change/main.2.dart @@ -0,0 +1,123 @@ +// 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 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L959 + +class X { + String name; + X(this.name); +} + +class A extends X { + A(name) : super(name); +} + +class B extends X { + B(name) : super(name); +} + +class C extends A { + C(name) : super(name); +} + +helper() {} + +var list; + +check() { + Expect.type(list[0]); + Expect.notType(list[0]); + Expect.notType(list[0]); + Expect.type(list[0]); + Expect.notType(list[1]); + Expect.type(list[1]); + Expect.notType(list[1]); + Expect.type(list[1]); + Expect.type(list[2]); + Expect.notType(list[2]); + Expect.type(list[2]); + Expect.type(list[2]); + Expect.notType(list[3]); + Expect.notType(list[3]); + Expect.notType(list[3]); + Expect.type(list[3]); +} + +Future main() async { + check(); + await hotReload(); + + helper(); + check(); + await hotReload(); + + // Revive the class B and make sure all allocated instances take + // their place in the inheritance hierarchy. + check(); +} + +/** DIFF **/ +/* + // Adapted from: + // https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L959 + +-class C { ++class X { + String name; +- C(this.name); +-} +- +-class X extends C { +- X(name) : super(name); ++ X(this.name); + } + + class A extends X { + A(name) : super(name); + } + +-helper() { +- list.add(new X('x')); ++class B extends X { ++ B(name) : super(name); + } + ++class C extends A { ++ C(name) : super(name); ++} ++ ++helper() {} ++ + var list; + + check() { + Expect.type(list[0]); +- Expect.type(list[0]); ++ Expect.notType(list[0]); ++ Expect.notType(list[0]); + Expect.type(list[0]); +- Expect.type(list[1]); +- Expect.type(list[1]); ++ Expect.notType(list[1]); ++ Expect.type(list[1]); ++ Expect.notType(list[1]); + Expect.type(list[1]); +- Expect.notType(list[2]); ++ Expect.type(list[2]); ++ Expect.notType(list[2]); + Expect.type(list[2]); +- Expect.notType(list[2]); ++ Expect.type(list[2]); + Expect.notType(list[3]); +- Expect.type(list[3]); ++ Expect.notType(list[3]); ++ Expect.notType(list[3]); + Expect.type(list[3]); + } + +*/