From 9e76983782442302251888fe098a734cbdc99836 Mon Sep 17 00:00:00 2001 From: "Lasse R.H. Nielsen" Date: Thu, 30 Mar 2023 20:34:09 +0000 Subject: [PATCH] Reland "Add more `interface` and `final` modifiers to `dart:core`." This is another reland of 4f8333e80e871bea1eb47b205b154864fb706b79. Third time is the charm. CoreLibraryReviewExempt: Reland of accepted CL. Change-Id: I4ea8326af91c168b044d252162571d3fe697e4b0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289826 Commit-Queue: Lasse Nielsen Reviewed-by: Nate Bosch Reviewed-by: Ben Konyi --- CHANGELOG.md | 31 ++++++++++++++++--- .../lib/src/util/link_implementation.dart | 2 +- pkg/compiler/lib/src/universe/class_set.dart | 2 +- .../test/inference/powerset_bits3_test.dart | 10 +++--- .../testcases/incremental/issue_32366.yaml | 4 +-- .../issue_32366.yaml.world.1.expect | 4 +-- .../issue_32366.yaml.world.2.expect | 4 +-- .../inference/try_catch_promotion.dart | 2 +- .../try_catch_promotion.dart.strong.expect | 6 ++-- ...h_promotion.dart.strong.transformed.expect | 6 ++-- ...atch_promotion.dart.textual_outline.expect | 2 +- ...otion.dart.textual_outline_modelled.expect | 2 +- .../try_catch_promotion.dart.weak.expect | 6 ++-- ...y_catch_promotion.dart.weak.modular.expect | 6 ++-- ...y_catch_promotion.dart.weak.outline.expect | 4 +-- ...tch_promotion.dart.weak.transformed.expect | 6 ++-- .../tests/concurrency/stress_test_list.json | 2 -- .../tests/vm/dart/regress_48323_1_test.dart | 2 +- .../src/collections/closable_iterator.dart | 2 +- sdk/lib/_internal/wasm/lib/js_helper.dart | 2 +- sdk/lib/collection/splay_tree.dart | 9 +++--- sdk/lib/core/annotations.dart | 2 +- sdk/lib/core/bigint.dart | 2 +- sdk/lib/core/comparable.dart | 2 +- sdk/lib/core/errors.dart | 4 +-- sdk/lib/core/exceptions.dart | 2 +- sdk/lib/core/iterator.dart | 2 +- sdk/lib/core/map.dart | 4 +-- sdk/lib/core/pattern.dart | 4 +-- sdk/lib/core/regexp.dart | 4 +-- sdk/lib/core/stacktrace.dart | 2 +- sdk/lib/core/string_sink.dart | 2 +- sdk/lib/core/weak.dart | 6 ++-- sdk/lib/internal/iterable.dart | 12 +++---- tests/language/regress/regress10561_test.dart | 16 ---------- tests/language/regress/regress9949_test.dart | 4 +-- tests/language/type/constants_test.dart | 2 +- .../language_2/regress/regress10561_test.dart | 18 ----------- .../language_2/regress/regress9949_test.dart | 4 +-- tests/language_2/type/constants_test.dart | 2 +- .../library_imports_deferred_test.dart | 18 +++++------ .../library_imports_deferred_test.dart | 18 +++++------ 42 files changed, 112 insertions(+), 132 deletions(-) delete mode 100644 tests/language/regress/regress10561_test.dart delete mode 100644 tests/language_2/regress/regress10561_test.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 58a915d2ffb..fcd795f54d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,13 +62,36 @@ a shared supertype locking them to a specific name for moving backwards. - **Breaking change when migrating code to Dart 3.0**: - Some changes to platform libraries only affect code when it is migrated + Some changes to platform libraries only affect code when that code is migrated to language version 3.0. - - The `Function` type can no longer be implemented. + - The `Function` type can no longer be implemented, extended or mixed in. Since Dart 2.0 writing `implements Function` has been allowed for backwards compatibility, but it has not had any effect. - In Dart 3.0, the `Function` type is `final` and cannot be implemented - by class-modifier aware code. + In Dart 3.0, the `Function` type is `final` and cannot be subtyped, + preventing code from mistakenly assuming it works. + - The following declarations can only be implemented, not extended: + * `Comparable` + * `Exception` + * `Iterator` + * `Pattern` + * `Match` + * `RegExp` + * `RegExpMatch` + * `StackTrace` + * `StringSink` + None of these declarations contained any implementation to inherit, + and are marked as `interface` to signify that they are only intended + as interfaces. + - The following declarations can no longer be implemented or extended: + * `MapEntry` + * `OutOfMemoryError` + * `StackOverflowError` + * `Expando` + * `WeakReference` + * `Finalizer` + The `MapEntry` value class is restricted to enable later optimizations. + The remaining classes are tightly coupled to the platform and not + intended to be subclassed or implemented. [#49529]: https://github.com/dart-lang/sdk/issues/49529 [`List.filled`]: https://api.dart.dev/stable/2.18.6/dart-core/List/List.filled.html diff --git a/pkg/_fe_analyzer_shared/lib/src/util/link_implementation.dart b/pkg/_fe_analyzer_shared/lib/src/util/link_implementation.dart index ecf1044f45f..e5921816785 100644 --- a/pkg/_fe_analyzer_shared/lib/src/util/link_implementation.dart +++ b/pkg/_fe_analyzer_shared/lib/src/util/link_implementation.dart @@ -31,7 +31,7 @@ class LinkIterator implements Iterator { typedef T Transformation(S input); -class MappedLinkIterator extends Iterator { +class MappedLinkIterator implements Iterator { Transformation _transformation; Link _link; T? _current; diff --git a/pkg/compiler/lib/src/universe/class_set.dart b/pkg/compiler/lib/src/universe/class_set.dart index acb9ae9139e..ea98bdec49f 100644 --- a/pkg/compiler/lib/src/universe/class_set.dart +++ b/pkg/compiler/lib/src/universe/class_set.dart @@ -967,7 +967,7 @@ class SubtypesIterable extends IterableBase { } /// Iterator for the subtypes in a [ClassSet]. -class SubtypesIterator extends Iterator { +class SubtypesIterator implements Iterator { final SubtypesIterable iterable; Iterator? elements; Iterator? hierarchyNodes; diff --git a/pkg/compiler/test/inference/powerset_bits3_test.dart b/pkg/compiler/test/inference/powerset_bits3_test.dart index 655de6a8347..f0bfd2a47c5 100644 --- a/pkg/compiler/test/inference/powerset_bits3_test.dart +++ b/pkg/compiler/test/inference/powerset_bits3_test.dart @@ -13,19 +13,19 @@ import '../helpers/element_lookup.dart'; import 'package:compiler/src/util/memory_compiler.dart'; const String CODE = """ -class A extends Comparable { +class A implements Comparable { int compareTo(x) { return 0; } } -class B extends Comparable { +class B implements Comparable { int compareTo(x) { return 0; } } -class C extends Comparable { +class C implements Comparable { int compareTo(x) { return 0; } } -class D extends Comparable { +class D implements Comparable { int compareTo(x) { return 0; } } -class E extends Comparable { +class E implements Comparable { int compareTo(x) { return 0; } } diff --git a/pkg/front_end/testcases/incremental/issue_32366.yaml b/pkg/front_end/testcases/incremental/issue_32366.yaml index 3fc46c3feb0..4108b175fb0 100644 --- a/pkg/front_end/testcases/incremental/issue_32366.yaml +++ b/pkg/front_end/testcases/incremental/issue_32366.yaml @@ -8,7 +8,7 @@ worlds: - entry: main.dart sources: main.dart: | - abstract class AIterator extends Iterator { + abstract class AIterator implements Iterator { } class Foo { final a; @@ -25,7 +25,7 @@ worlds: errors: true sources: main.dart: | - abstract class BIterator extends Iterator { + abstract class BIterator implements Iterator { } class Foo { final a kjsdf ksjdf ; diff --git a/pkg/front_end/testcases/incremental/issue_32366.yaml.world.1.expect b/pkg/front_end/testcases/incremental/issue_32366.yaml.world.1.expect index bc95a7c5fcf..3ac341d4355 100644 --- a/pkg/front_end/testcases/incremental/issue_32366.yaml.world.1.expect +++ b/pkg/front_end/testcases/incremental/issue_32366.yaml.world.1.expect @@ -1,9 +1,9 @@ main = main::main; library from "org-dartlang-test:///main.dart" as main { - abstract class AIterator extends dart.core::Iterator { + abstract class AIterator extends dart.core::Object implements dart.core::Iterator { synthetic constructor •() → main::AIterator - : super dart.core::Iterator::•() + : super dart.core::Object::•() ; } class Foo extends dart.core::Object { diff --git a/pkg/front_end/testcases/incremental/issue_32366.yaml.world.2.expect b/pkg/front_end/testcases/incremental/issue_32366.yaml.world.2.expect index 84dceba1628..b9a726ac08a 100644 --- a/pkg/front_end/testcases/incremental/issue_32366.yaml.world.2.expect +++ b/pkg/front_end/testcases/incremental/issue_32366.yaml.world.2.expect @@ -30,9 +30,9 @@ library from "org-dartlang-test:///main.dart" as main { // ^ // - abstract class BIterator extends dart.core::Iterator { + abstract class BIterator extends dart.core::Object implements dart.core::Iterator { synthetic constructor •() → main::BIterator - : super dart.core::Iterator::•() + : super dart.core::Object::•() ; } class Foo extends dart.core::Object { diff --git a/pkg/front_end/testcases/inference/try_catch_promotion.dart b/pkg/front_end/testcases/inference/try_catch_promotion.dart index 17f1e21d1ce..abdc8f392c4 100644 --- a/pkg/front_end/testcases/inference/try_catch_promotion.dart +++ b/pkg/front_end/testcases/inference/try_catch_promotion.dart @@ -11,7 +11,7 @@ class C {} class D extends C {} -class E extends StackTrace {} +class E implements StackTrace {} void test(void f()) { try { diff --git a/pkg/front_end/testcases/inference/try_catch_promotion.dart.strong.expect b/pkg/front_end/testcases/inference/try_catch_promotion.dart.strong.expect index c5c1336ed8c..cba89691040 100644 --- a/pkg/front_end/testcases/inference/try_catch_promotion.dart.strong.expect +++ b/pkg/front_end/testcases/inference/try_catch_promotion.dart.strong.expect @@ -29,12 +29,11 @@ class D extends self::C { : super self::C::•() ; } -class E extends core::StackTrace { +class E extends core::Object implements core::StackTrace { synthetic constructor •() → self::E* - : super core::StackTrace::•() + : super core::Object::•() ; abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod - abstract member-signature method toString() → core::String*; -> core::StackTrace::toString abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf @@ -42,6 +41,7 @@ class E extends core::StackTrace { abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::== abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode + abstract member-signature method toString() → core::String*; -> core::Object::toString abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType } static method test(() →* void f) → void { diff --git a/pkg/front_end/testcases/inference/try_catch_promotion.dart.strong.transformed.expect b/pkg/front_end/testcases/inference/try_catch_promotion.dart.strong.transformed.expect index c5c1336ed8c..cba89691040 100644 --- a/pkg/front_end/testcases/inference/try_catch_promotion.dart.strong.transformed.expect +++ b/pkg/front_end/testcases/inference/try_catch_promotion.dart.strong.transformed.expect @@ -29,12 +29,11 @@ class D extends self::C { : super self::C::•() ; } -class E extends core::StackTrace { +class E extends core::Object implements core::StackTrace { synthetic constructor •() → self::E* - : super core::StackTrace::•() + : super core::Object::•() ; abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod - abstract member-signature method toString() → core::String*; -> core::StackTrace::toString abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf @@ -42,6 +41,7 @@ class E extends core::StackTrace { abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::== abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode + abstract member-signature method toString() → core::String*; -> core::Object::toString abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType } static method test(() →* void f) → void { diff --git a/pkg/front_end/testcases/inference/try_catch_promotion.dart.textual_outline.expect b/pkg/front_end/testcases/inference/try_catch_promotion.dart.textual_outline.expect index 654304607db..df1115e37a9 100644 --- a/pkg/front_end/testcases/inference/try_catch_promotion.dart.textual_outline.expect +++ b/pkg/front_end/testcases/inference/try_catch_promotion.dart.textual_outline.expect @@ -5,7 +5,7 @@ class C {} class D extends C {} -class E extends StackTrace {} +class E implements StackTrace {} void test(void f()) {} main() {} diff --git a/pkg/front_end/testcases/inference/try_catch_promotion.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/inference/try_catch_promotion.dart.textual_outline_modelled.expect index ab3f6f6f4de..2db370d3b1e 100644 --- a/pkg/front_end/testcases/inference/try_catch_promotion.dart.textual_outline_modelled.expect +++ b/pkg/front_end/testcases/inference/try_catch_promotion.dart.textual_outline_modelled.expect @@ -5,7 +5,7 @@ class C {} class D extends C {} -class E extends StackTrace {} +class E implements StackTrace {} main() {} void test(void f()) {} diff --git a/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.expect b/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.expect index bf9fab61431..f035cfe145e 100644 --- a/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.expect +++ b/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.expect @@ -22,12 +22,11 @@ class D extends self::C { : super self::C::•() ; } -class E extends core::StackTrace { +class E extends core::Object implements core::StackTrace { synthetic constructor •() → self::E* - : super core::StackTrace::•() + : super core::Object::•() ; abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod - abstract member-signature method toString() → core::String*; -> core::StackTrace::toString abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf @@ -35,6 +34,7 @@ class E extends core::StackTrace { abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::== abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode + abstract member-signature method toString() → core::String*; -> core::Object::toString abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType } static method test(() →* void f) → void { diff --git a/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.modular.expect b/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.modular.expect index bf9fab61431..f035cfe145e 100644 --- a/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.modular.expect +++ b/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.modular.expect @@ -22,12 +22,11 @@ class D extends self::C { : super self::C::•() ; } -class E extends core::StackTrace { +class E extends core::Object implements core::StackTrace { synthetic constructor •() → self::E* - : super core::StackTrace::•() + : super core::Object::•() ; abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod - abstract member-signature method toString() → core::String*; -> core::StackTrace::toString abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf @@ -35,6 +34,7 @@ class E extends core::StackTrace { abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::== abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode + abstract member-signature method toString() → core::String*; -> core::Object::toString abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType } static method test(() →* void f) → void { diff --git a/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.outline.expect b/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.outline.expect index 0bb2c870c34..fb937f03a7c 100644 --- a/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.outline.expect +++ b/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.outline.expect @@ -20,11 +20,10 @@ class D extends self::C { synthetic constructor •() → self::D* ; } -class E extends core::StackTrace { +class E extends core::Object implements core::StackTrace { synthetic constructor •() → self::E* ; abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod - abstract member-signature method toString() → core::String*; -> core::StackTrace::toString abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf @@ -32,6 +31,7 @@ class E extends core::StackTrace { abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::== abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode + abstract member-signature method toString() → core::String*; -> core::Object::toString abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType } static method test(() →* void f) → void diff --git a/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.transformed.expect b/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.transformed.expect index bf9fab61431..f035cfe145e 100644 --- a/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.transformed.expect +++ b/pkg/front_end/testcases/inference/try_catch_promotion.dart.weak.transformed.expect @@ -22,12 +22,11 @@ class D extends self::C { : super self::C::•() ; } -class E extends core::StackTrace { +class E extends core::Object implements core::StackTrace { synthetic constructor •() → self::E* - : super core::StackTrace::•() + : super core::Object::•() ; abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod - abstract member-signature method toString() → core::String*; -> core::StackTrace::toString abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf @@ -35,6 +34,7 @@ class E extends core::StackTrace { abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::== abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode + abstract member-signature method toString() → core::String*; -> core::Object::toString abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType } static method test(() →* void f) → void { diff --git a/runtime/tests/concurrency/stress_test_list.json b/runtime/tests/concurrency/stress_test_list.json index 6984088818b..4ce5cb9b741 100644 --- a/runtime/tests/concurrency/stress_test_list.json +++ b/runtime/tests/concurrency/stress_test_list.json @@ -2174,7 +2174,6 @@ "../../../tests/language/regress/r24720_test.dart", "../../../tests/language/regress/regress10204_test.dart", "../../../tests/language/regress/regress10321_test.dart", - "../../../tests/language/regress/regress10561_test.dart", "../../../tests/language/regress/regress10581_test.dart", "../../../tests/language/regress/regress10721_test.dart", "../../../tests/language/regress/regress10747_test.dart", @@ -5496,7 +5495,6 @@ "../../../tests/language_2/regress/r24720_test.dart", "../../../tests/language_2/regress/regress10204_test.dart", "../../../tests/language_2/regress/regress10321_test.dart", - "../../../tests/language_2/regress/regress10561_test.dart", "../../../tests/language_2/regress/regress10581_test.dart", "../../../tests/language_2/regress/regress10721_test.dart", "../../../tests/language_2/regress/regress10747_test.dart", diff --git a/runtime/tests/vm/dart/regress_48323_1_test.dart b/runtime/tests/vm/dart/regress_48323_1_test.dart index d9c7595ac84..65d3c201112 100644 --- a/runtime/tests/vm/dart/regress_48323_1_test.dart +++ b/runtime/tests/vm/dart/regress_48323_1_test.dart @@ -6,7 +6,7 @@ // Verifies that class finalization doesn't crash when seeing // superclass with type arguments which were not finalized yet. -abstract class GraphNode extends Comparable { +abstract class GraphNode implements Comparable { int compareTo(dynamic other) => 0; } diff --git a/samples/ffi/sqlite/lib/src/collections/closable_iterator.dart b/samples/ffi/sqlite/lib/src/collections/closable_iterator.dart index a86a58b2ad5..49abbd2131a 100644 --- a/samples/ffi/sqlite/lib/src/collections/closable_iterator.dart +++ b/samples/ffi/sqlite/lib/src/collections/closable_iterator.dart @@ -7,7 +7,7 @@ /// [ClosableIterator]s often use resources which should be freed after use. /// The consumer of the iterator can either manually [close] the iterator, or /// consume all elements on which the iterator will automatically be closed. -abstract class ClosableIterator extends Iterator { +abstract class ClosableIterator implements Iterator { /// Close this iterator. void close(); diff --git a/sdk/lib/_internal/wasm/lib/js_helper.dart b/sdk/lib/_internal/wasm/lib/js_helper.dart index 11aa9dda725..4044abf4dc5 100644 --- a/sdk/lib/_internal/wasm/lib/js_helper.dart +++ b/sdk/lib/_internal/wasm/lib/js_helper.dart @@ -99,7 +99,7 @@ extension JSObjectExtension on JSObject { external void operator []=(JSString key, JSAny? value); } -class JSArrayIteratorAdapter extends Iterator { +class JSArrayIteratorAdapter implements Iterator { final JSArray array; int index = -1; diff --git a/sdk/lib/collection/splay_tree.dart b/sdk/lib/collection/splay_tree.dart index 1ab21dbc4d3..55b6402f492 100644 --- a/sdk/lib/collection/splay_tree.dart +++ b/sdk/lib/collection/splay_tree.dart @@ -26,8 +26,8 @@ class _SplayTreeSetNode extends _SplayTreeNode> { /// /// A [_SplayTreeNode] that also contains a value, /// and which implements [MapEntry]. -class _SplayTreeMapNode extends _SplayTreeNode> - implements MapEntry { +class _SplayTreeMapNode + extends _SplayTreeNode> { final V value; _SplayTreeMapNode(K key, this.value) : super(key); @@ -35,8 +35,6 @@ class _SplayTreeMapNode extends _SplayTreeNode> _SplayTreeMapNode(key, value) .._left = _left .._right = _right; - - String toString() => "MapEntry($key: $value)"; } /// A splay tree is a self-balancing binary search tree. @@ -836,7 +834,8 @@ class _SplayTreeValueIterator class _SplayTreeMapEntryIterator extends _SplayTreeIterator, MapEntry> { _SplayTreeMapEntryIterator(SplayTreeMap tree) : super(tree); - MapEntry _getValue(_SplayTreeMapNode node) => node; + MapEntry _getValue(_SplayTreeMapNode node) => + MapEntry(node.key, node.value); // Replaces the value of the current node. void _replaceValue(V value) { diff --git a/sdk/lib/core/annotations.dart b/sdk/lib/core/annotations.dart index 8183375e0f3..e437d90bd15 100644 --- a/sdk/lib/core/annotations.dart +++ b/sdk/lib/core/annotations.dart @@ -147,7 +147,7 @@ const Object override = _Override(); /// function `foo` is annotated with a pragma 'other-pragma' /// specific to OtherTool. @pragma('vm:entry-point') -class pragma { +final class pragma { /// The name of the hint. /// /// A string that is recognized by one or more tools, or such a string prefixed diff --git a/sdk/lib/core/bigint.dart b/sdk/lib/core/bigint.dart index e5a871c750d..28da09dbff4 100644 --- a/sdk/lib/core/bigint.dart +++ b/sdk/lib/core/bigint.dart @@ -41,7 +41,7 @@ part of dart.core; /// * [num]: The super class for [int] and [double]. /// * [Numbers](https://dart.dev/guides/language/numbers) in /// [A tour of the Dart language](https://dart.dev/guides/language/language-tour). -abstract class BigInt implements Comparable { +abstract final class BigInt implements Comparable { /// A big integer with the numerical value 0. external static BigInt get zero; diff --git a/sdk/lib/core/comparable.dart b/sdk/lib/core/comparable.dart index 67df844a0c9..3d0bd51be8f 100644 --- a/sdk/lib/core/comparable.dart +++ b/sdk/lib/core/comparable.dart @@ -66,7 +66,7 @@ typedef Comparator = int Function(T a, T b); /// The [DateTime] class has no comparison operators, instead it has the more /// precisely named [DateTime.isBefore] and [DateTime.isAfter], which both /// agree with [DateTime.compareTo]. -abstract class Comparable { +abstract interface class Comparable { /// Compares this object to another object. /// /// Returns a value like a [Comparator] when comparing `this` to [other]. diff --git a/sdk/lib/core/errors.dart b/sdk/lib/core/errors.dart index d54dcd0400c..368891cae77 100644 --- a/sdk/lib/core/errors.dart +++ b/sdk/lib/core/errors.dart @@ -596,7 +596,7 @@ class ConcurrentModificationError extends Error { } /// Error that the platform can use in case of memory shortage. -class OutOfMemoryError implements Error { +final class OutOfMemoryError implements Error { @pragma("vm:entry-point") const OutOfMemoryError(); String toString() => "Out of Memory"; @@ -605,7 +605,7 @@ class OutOfMemoryError implements Error { } /// Error that the platform can use in case of stack overflow. -class StackOverflowError implements Error { +final class StackOverflowError implements Error { @pragma("vm:entry-point") const StackOverflowError(); String toString() => "Stack Overflow"; diff --git a/sdk/lib/core/exceptions.dart b/sdk/lib/core/exceptions.dart index c4c441bc1d8..c7a064d8ba1 100644 --- a/sdk/lib/core/exceptions.dart +++ b/sdk/lib/core/exceptions.dart @@ -20,7 +20,7 @@ part of dart.core; /// For failures that are not intended to be caught, use [Error] /// and its subclasses. @pragma('flutter:keep-to-string-in-subtypes') -abstract class Exception { +abstract interface class Exception { factory Exception([var message]) => _Exception(message); } diff --git a/sdk/lib/core/iterator.dart b/sdk/lib/core/iterator.dart index a33e2733113..915e6220bb4 100644 --- a/sdk/lib/core/iterator.dart +++ b/sdk/lib/core/iterator.dart @@ -31,7 +31,7 @@ part of dart.core; /// **See also:** /// [Iteration](https://dart.dev/guides/libraries/library-tour#iteration) /// in the [library tour](https://dart.dev/guides/libraries/library-tour) -abstract class Iterator { +abstract interface class Iterator { /// Advances the iterator to the next element of the iteration. /// /// Should be called before reading [current]. diff --git a/sdk/lib/core/map.dart b/sdk/lib/core/map.dart index ea609e03905..aa8646719af 100644 --- a/sdk/lib/core/map.dart +++ b/sdk/lib/core/map.dart @@ -468,9 +468,7 @@ abstract class Map { /// the `MapEntry` class will be changed to such a type, /// and will likely no longer be able to be implemented or extended /// by classes. -// TODO(lrn): Make this class `final` when class modifiers are introduced. -// Change to an `inline class` when those are available. -class MapEntry { +final class MapEntry { /// The key of the entry. /// /// ```dart diff --git a/sdk/lib/core/pattern.dart b/sdk/lib/core/pattern.dart index fbf70ea1b4c..9f6e34debdc 100644 --- a/sdk/lib/core/pattern.dart +++ b/sdk/lib/core/pattern.dart @@ -5,7 +5,7 @@ part of dart.core; /// An interface for basic searches within strings. -abstract class Pattern { +abstract interface class Pattern { /// Matches this pattern against the string repeatedly. /// /// If [start] is provided, matching will start at that index. @@ -82,7 +82,7 @@ abstract class Pattern { /// that were part of the matching. These are called _groups_ in the `Match` /// object. Some patterns may never have any groups, and their matches always /// have zero [groupCount]. -abstract class Match { +abstract interface class Match { /// The index in the string where the match starts. int get start; diff --git a/sdk/lib/core/regexp.dart b/sdk/lib/core/regexp.dart index 9ca82395f8e..921af06189c 100644 --- a/sdk/lib/core/regexp.dart +++ b/sdk/lib/core/regexp.dart @@ -213,7 +213,7 @@ part of dart.core; /// when the regexp does not find a match. /// Several guides to [improving the performance of regular expressions](https://www.google.com/search?q=performance+of+regular+expressions) /// exist on the internet. Use these as inspirations, too. -abstract class RegExp implements Pattern { +abstract interface class RegExp implements Pattern { /// Constructs a regular expression. /// /// Throws a [FormatException] if [source] does not follow valid regular @@ -469,7 +469,7 @@ abstract class RegExp implements Pattern { /// } /// ``` @Since("2.3") -abstract class RegExpMatch implements Match { +abstract interface class RegExpMatch implements Match { /// The string captured by the named capture group [name]. /// /// Returns the substring of the input that the diff --git a/sdk/lib/core/stacktrace.dart b/sdk/lib/core/stacktrace.dart index dbba199885d..24c8ea23abe 100644 --- a/sdk/lib/core/stacktrace.dart +++ b/sdk/lib/core/stacktrace.dart @@ -11,7 +11,7 @@ part of dart.core; /// /// These objects are created by the runtime, it is not possible to create /// them programmatically. -abstract class StackTrace { +abstract interface class StackTrace { /// A stack trace object with no information. /// /// This stack trace is used as the default in situations where diff --git a/sdk/lib/core/string_sink.dart b/sdk/lib/core/string_sink.dart index 565ce563255..35013a47002 100644 --- a/sdk/lib/core/string_sink.dart +++ b/sdk/lib/core/string_sink.dart @@ -4,7 +4,7 @@ part of dart.core; -abstract class StringSink { +abstract interface class StringSink { /// Writes the string representation of [object]. /// /// Converts [object] to a string using `object.toString()`. diff --git a/sdk/lib/core/weak.dart b/sdk/lib/core/weak.dart index 0ae32c7013d..0c74cd92820 100644 --- a/sdk/lib/core/weak.dart +++ b/sdk/lib/core/weak.dart @@ -30,7 +30,7 @@ part of dart.core; /// There is no restriction on other classes, even for compile time constant /// objects. Be careful if adding expando properties to compile time constants, /// since they will stay alive forever. -class Expando { +final class Expando { /// The name of the this [Expando] as passed to the constructor. /// /// If no name was passed to the constructor, the value is the `null` value. @@ -123,7 +123,7 @@ class Expando { /// } /// ``` @Since("2.17") -abstract class WeakReference { +abstract final class WeakReference { /// Creates a [WeakReference] pointing to the given [target]. /// /// The [target] must be an object supported as an [Expando] key, @@ -220,7 +220,7 @@ abstract class WeakReference { /// function rather than a Dart function, use `dart:ffi`'s [NativeFinalizer] /// instead. @Since("2.17") -abstract class Finalizer { +abstract final class Finalizer { /// Creates a finalizer with the given finalization callback. /// /// The [callback] is bound to the current zone diff --git a/sdk/lib/internal/iterable.dart b/sdk/lib/internal/iterable.dart index 4dbd20a9039..15f9f6cfa62 100644 --- a/sdk/lib/internal/iterable.dart +++ b/sdk/lib/internal/iterable.dart @@ -381,7 +381,7 @@ class EfficientLengthMappedIterable extends MappedIterable : super._(iterable, function); } -class MappedIterator extends Iterator { +class MappedIterator implements Iterator { T? _current; final Iterator _iterator; final _Transformation _f; @@ -430,7 +430,7 @@ class WhereIterable extends Iterable { MappedIterable._(this, toElement); } -class WhereIterator extends Iterator { +class WhereIterator implements Iterator { final Iterator _iterator; final _ElementPredicate _f; @@ -522,7 +522,7 @@ class EfficientLengthTakeIterable extends TakeIterable } } -class TakeIterator extends Iterator { +class TakeIterator implements Iterator { final Iterator _iterator; int _remaining; @@ -560,7 +560,7 @@ class TakeWhileIterable extends Iterable { } } -class TakeWhileIterator extends Iterator { +class TakeWhileIterator implements Iterator { final Iterator _iterator; final _ElementPredicate _f; bool _isFinished = false; @@ -631,7 +631,7 @@ int _checkCount(int count) { return count; } -class SkipIterator extends Iterator { +class SkipIterator implements Iterator { final Iterator _iterator; int _skipCount; @@ -659,7 +659,7 @@ class SkipWhileIterable extends Iterable { } } -class SkipWhileIterator extends Iterator { +class SkipWhileIterator implements Iterator { final Iterator _iterator; final _ElementPredicate _f; bool _hasSkipped = false; diff --git a/tests/language/regress/regress10561_test.dart b/tests/language/regress/regress10561_test.dart deleted file mode 100644 index 16e0cca67f5..00000000000 --- a/tests/language/regress/regress10561_test.dart +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2013, 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. - -// Regression test for dart2js that used to miscompile classes -// extending HashMap, because HashMap is patched. - -import "package:expect/expect.dart"; - -import 'dart:collection'; - -class Foo extends Expando {} - -main() { - Expect.isNull(new Foo()[new Object()]); -} diff --git a/tests/language/regress/regress9949_test.dart b/tests/language/regress/regress9949_test.dart index 38ff6edb07e..3bd0f9a79f6 100644 --- a/tests/language/regress/regress9949_test.dart +++ b/tests/language/regress/regress9949_test.dart @@ -8,11 +8,11 @@ import "package:expect/expect.dart"; import 'dart:collection'; -class Crash extends Expando { +class Crash extends StringBuffer { Crash() : super(); } void main() { Crash expando = new Crash(); - Expect.isTrue(expando is Expando); + Expect.isTrue(expando is StringBuffer); } diff --git a/tests/language/type/constants_test.dart b/tests/language/type/constants_test.dart index adcab5e2d68..42c41a2d2ed 100644 --- a/tests/language/type/constants_test.dart +++ b/tests/language/type/constants_test.dart @@ -8,7 +8,7 @@ // constant map keys and case expressions, and the value of non-constant type // literals are not. -import "dart:collection" deferred as prefix; +import "dart:collection" deferred as prefix show HashSet; main(args) { testSwitch(args); diff --git a/tests/language_2/regress/regress10561_test.dart b/tests/language_2/regress/regress10561_test.dart deleted file mode 100644 index 0961a2e7f7e..00000000000 --- a/tests/language_2/regress/regress10561_test.dart +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2013, 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. - -// @dart = 2.9 - -// Regression test for dart2js that used to miscompile classes -// extending HashMap, because HashMap is patched. - -import "package:expect/expect.dart"; - -import 'dart:collection'; - -class Foo extends Expando {} - -main() { - Expect.isNull(new Foo()[new Object()]); -} diff --git a/tests/language_2/regress/regress9949_test.dart b/tests/language_2/regress/regress9949_test.dart index 0054039ee3e..b3d50c45ca6 100644 --- a/tests/language_2/regress/regress9949_test.dart +++ b/tests/language_2/regress/regress9949_test.dart @@ -10,11 +10,11 @@ import "package:expect/expect.dart"; import 'dart:collection'; -class Crash extends Expando { +class Crash extends StringBuffer { Crash() : super(); } void main() { Crash expando = new Crash(); - Expect.isTrue(expando is Expando); + Expect.isTrue(expando is StringBuffer); } diff --git a/tests/language_2/type/constants_test.dart b/tests/language_2/type/constants_test.dart index cda34ff8ff7..95f71c3991f 100644 --- a/tests/language_2/type/constants_test.dart +++ b/tests/language_2/type/constants_test.dart @@ -8,7 +8,7 @@ // constant map keys and case expressions, and the value of non-constant type // literals are not. -import "dart:collection" deferred as prefix; +import "dart:collection" deferred as prefix show HashSet; main(args) { testSwitch(args); diff --git a/tests/lib/mirrors/library_imports_deferred_test.dart b/tests/lib/mirrors/library_imports_deferred_test.dart index ab2668da781..1d28248cc75 100644 --- a/tests/lib/mirrors/library_imports_deferred_test.dart +++ b/tests/lib/mirrors/library_imports_deferred_test.dart @@ -8,31 +8,29 @@ import 'dart:mirrors'; import 'package:expect/expect.dart'; import 'stringify.dart'; -import 'dart:collection' as eagercollection; -import 'dart:collection' deferred as lazycollection; +import 'dart:math' as eagermath; +import 'dart:math' deferred as lazymath; test(MirrorSystem mirrors) { LibraryMirror thisLibrary = mirrors.findLibrary(#test.library_imports_deferred); - LibraryMirror collection = mirrors.findLibrary(#dart.collection); + LibraryMirror math = mirrors.findLibrary(#dart.math); var importsOfCollection = thisLibrary.libraryDependencies - .where((dep) => dep.targetLibrary == collection) + .where((dep) => dep.targetLibrary == math) .toList(); Expect.equals(2, importsOfCollection.length); Expect.notEquals(importsOfCollection[0].isDeferred, importsOfCollection[1].isDeferred); // One deferred, one not. - // Only collection is defer-imported. + // Only math is defer-imported. LibraryDependencyMirror dep = thisLibrary.libraryDependencies.singleWhere((dep) => dep.isDeferred); - Expect.equals(collection, dep.targetLibrary); + Expect.equals(math, dep.targetLibrary); Expect.stringEquals( - 'import dart.collection as eagercollection\n' - 'import dart.collection deferred as lazycollection\n' - ' hide loadLibrary\n' - 'import dart.core\n' + 'import dart.math as eagermath\n' + 'import dart.math deferred as lazymath\n' 'import dart.mirrors\n' 'import expect\n' 'import test.stringify\n', diff --git a/tests/lib_2/mirrors/library_imports_deferred_test.dart b/tests/lib_2/mirrors/library_imports_deferred_test.dart index 977564f0528..d2ca36ee3e3 100644 --- a/tests/lib_2/mirrors/library_imports_deferred_test.dart +++ b/tests/lib_2/mirrors/library_imports_deferred_test.dart @@ -10,31 +10,29 @@ import 'dart:mirrors'; import 'package:expect/expect.dart'; import 'stringify.dart'; -import 'dart:collection' as eagercollection; -import 'dart:collection' deferred as lazycollection; +import 'dart:math' as eagermath; +import 'dart:math' deferred as lazymath; test(MirrorSystem mirrors) { LibraryMirror thisLibrary = mirrors.findLibrary(#test.library_imports_deferred); - LibraryMirror collection = mirrors.findLibrary(#dart.collection); + LibraryMirror math = mirrors.findLibrary(#dart.math); var importsOfCollection = thisLibrary.libraryDependencies - .where((dep) => dep.targetLibrary == collection) + .where((dep) => dep.targetLibrary == math) .toList(); Expect.equals(2, importsOfCollection.length); Expect.notEquals(importsOfCollection[0].isDeferred, importsOfCollection[1].isDeferred); // One deferred, one not. - // Only collection is defer-imported. + // Only math is defer-imported. LibraryDependencyMirror dep = thisLibrary.libraryDependencies.singleWhere((dep) => dep.isDeferred); - Expect.equals(collection, dep.targetLibrary); + Expect.equals(math, dep.targetLibrary); Expect.stringEquals( - 'import dart.collection as eagercollection\n' - 'import dart.collection deferred as lazycollection\n' - ' hide loadLibrary\n' - 'import dart.core\n' + 'import dart.math as eagermath\n' + 'import dart.math deferred as lazymath\n' 'import dart.mirrors\n' 'import expect\n' 'import test.stringify\n',