1
0
mirror of https://github.com/dart-lang/sdk synced 2024-07-08 12:06:26 +00:00

Add more interface and final modifiers to dart:core.

Make intent explicit for classes which are intended as interfaces,
or which are not intended to be subclassed.

Mainly classes which are pure interfaces are marked as such,
and platform-specific classes not intended for subclassing
are made `final`.

The `final` classes includes `BigInt`, which is written to assume
that arguments inherit its private members
(it runs `_ensureSystemBigInt` on arguments).

It also includes the `Expando`, `WeakReference` and `Finalizer` classes,
which are just intended as stand-alone implementation classes for accessing
platform-specific functionality.

Change-Id: Ib770c265edff127a289a67fe72d15b9ff0499407
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287180
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Lasse R.H. Nielsen 2023-03-09 12:31:08 +00:00 committed by Commit Queue
parent 615e44821a
commit 4f8333e80e
39 changed files with 95 additions and 111 deletions

View File

@ -61,13 +61,36 @@
a shared supertype locking them to a specific name for moving backwards. a shared supertype locking them to a specific name for moving backwards.
- **Breaking change when migrating code to Dart 3.0**: - **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. 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 Since Dart 2.0 writing `implements Function` has been allowed
for backwards compatibility, but it has not had any effect. for backwards compatibility, but it has not had any effect.
In Dart 3.0, the `Function` type is `final` and cannot be implemented In Dart 3.0, the `Function` type is `final` and cannot be subtyped,
by class-modifier aware code. 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 [#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 [`List.filled`]: https://api.dart.dev/stable/2.18.6/dart-core/List/List.filled.html

View File

@ -31,7 +31,7 @@ class LinkIterator<T> implements Iterator<T> {
typedef T Transformation<S, T>(S input); typedef T Transformation<S, T>(S input);
class MappedLinkIterator<S, T> extends Iterator<T> { class MappedLinkIterator<S, T> implements Iterator<T> {
Transformation<S, T> _transformation; Transformation<S, T> _transformation;
Link<S> _link; Link<S> _link;
T? _current; T? _current;

View File

@ -967,7 +967,7 @@ class SubtypesIterable extends IterableBase<ClassEntity> {
} }
/// Iterator for the subtypes in a [ClassSet]. /// Iterator for the subtypes in a [ClassSet].
class SubtypesIterator extends Iterator<ClassEntity> { class SubtypesIterator implements Iterator<ClassEntity> {
final SubtypesIterable iterable; final SubtypesIterable iterable;
Iterator<ClassEntity>? elements; Iterator<ClassEntity>? elements;
Iterator<ClassHierarchyNode>? hierarchyNodes; Iterator<ClassHierarchyNode>? hierarchyNodes;

View File

@ -13,19 +13,19 @@ import '../helpers/element_lookup.dart';
import 'package:compiler/src/util/memory_compiler.dart'; import 'package:compiler/src/util/memory_compiler.dart';
const String CODE = """ const String CODE = """
class A extends Comparable { class A implements Comparable {
int compareTo(x) { return 0; } int compareTo(x) { return 0; }
} }
class B extends Comparable { class B implements Comparable {
int compareTo(x) { return 0; } int compareTo(x) { return 0; }
} }
class C extends Comparable { class C implements Comparable {
int compareTo(x) { return 0; } int compareTo(x) { return 0; }
} }
class D extends Comparable { class D implements Comparable {
int compareTo(x) { return 0; } int compareTo(x) { return 0; }
} }
class E extends Comparable { class E implements Comparable {
int compareTo(x) { return 0; } int compareTo(x) { return 0; }
} }

View File

@ -8,7 +8,7 @@ worlds:
- entry: main.dart - entry: main.dart
sources: sources:
main.dart: | main.dart: |
abstract class AIterator extends Iterator { abstract class AIterator implements Iterator {
} }
class Foo { class Foo {
final a; final a;
@ -25,7 +25,7 @@ worlds:
errors: true errors: true
sources: sources:
main.dart: | main.dart: |
abstract class BIterator extends Iterator { abstract class BIterator implements Iterator {
} }
class Foo { class Foo {
final a kjsdf ksjdf ; final a kjsdf ksjdf ;

View File

@ -1,9 +1,9 @@
main = main::main; main = main::main;
library from "org-dartlang-test:///main.dart" as main { library from "org-dartlang-test:///main.dart" as main {
abstract class AIterator extends dart.core::Iterator<dynamic> { abstract class AIterator extends dart.core::Object implements dart.core::Iterator<dynamic> {
synthetic constructor •() → main::AIterator synthetic constructor •() → main::AIterator
: super dart.core::Iterator::•() : super dart.core::Object::•()
; ;
} }
class Foo extends dart.core::Object { class Foo extends dart.core::Object {

View File

@ -30,9 +30,9 @@ library from "org-dartlang-test:///main.dart" as main {
// ^ // ^
// //
abstract class BIterator extends dart.core::Iterator<dynamic> { abstract class BIterator extends dart.core::Object implements dart.core::Iterator<dynamic> {
synthetic constructor •() → main::BIterator synthetic constructor •() → main::BIterator
: super dart.core::Iterator::•() : super dart.core::Object::•()
; ;
} }
class Foo extends dart.core::Object { class Foo extends dart.core::Object {

View File

@ -11,7 +11,7 @@ class C {}
class D extends C {} class D extends C {}
class E extends StackTrace {} class E implements StackTrace {}
void test(void f()) { void test(void f()) {
try { try {

View File

@ -29,12 +29,11 @@ class D extends self::C {
: super self::C::•() : super self::C::•()
; ;
} }
class E extends core::StackTrace { class E extends core::Object implements core::StackTrace {
synthetic constructor •() → self::E* 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 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 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 _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf 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 method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::== abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode 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 abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
} }
static method test(() →* void f) → void { static method test(() →* void f) → void {

View File

@ -29,12 +29,11 @@ class D extends self::C {
: super self::C::•() : super self::C::•()
; ;
} }
class E extends core::StackTrace { class E extends core::Object implements core::StackTrace {
synthetic constructor •() → self::E* 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 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 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 _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf 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 method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::== abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode 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 abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
} }
static method test(() →* void f) → void { static method test(() →* void f) → void {

View File

@ -5,7 +5,7 @@ class C {}
class D extends C {} class D extends C {}
class E extends StackTrace {} class E implements StackTrace {}
void test(void f()) {} void test(void f()) {}
main() {} main() {}

View File

@ -5,7 +5,7 @@ class C {}
class D extends C {} class D extends C {}
class E extends StackTrace {} class E implements StackTrace {}
main() {} main() {}
void test(void f()) {} void test(void f()) {}

View File

@ -22,12 +22,11 @@ class D extends self::C {
: super self::C::•() : super self::C::•()
; ;
} }
class E extends core::StackTrace { class E extends core::Object implements core::StackTrace {
synthetic constructor •() → self::E* 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 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 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 _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf 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 method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::== abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode 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 abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
} }
static method test(() →* void f) → void { static method test(() →* void f) → void {

View File

@ -22,12 +22,11 @@ class D extends self::C {
: super self::C::•() : super self::C::•()
; ;
} }
class E extends core::StackTrace { class E extends core::Object implements core::StackTrace {
synthetic constructor •() → self::E* 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 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 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 _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf 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 method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::== abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode 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 abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
} }
static method test(() →* void f) → void { static method test(() →* void f) → void {

View File

@ -20,11 +20,10 @@ class D extends self::C {
synthetic constructor •() → self::D* synthetic constructor •() → self::D*
; ;
} }
class E extends core::StackTrace { class E extends core::Object implements core::StackTrace {
synthetic constructor •() → self::E* synthetic constructor •() → self::E*
; ;
abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod 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 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 _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf 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 method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::== abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode 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 abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
} }
static method test(() →* void f) → void static method test(() →* void f) → void

View File

@ -22,12 +22,11 @@ class D extends self::C {
: super self::C::•() : super self::C::•()
; ;
} }
class E extends core::StackTrace { class E extends core::Object implements core::StackTrace {
synthetic constructor •() → self::E* 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 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 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 _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf 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 method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::== abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode 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 abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
} }
static method test(() →* void f) → void { static method test(() →* void f) → void {

View File

@ -2176,7 +2176,6 @@
"../../../tests/language/regress/r24720_test.dart", "../../../tests/language/regress/r24720_test.dart",
"../../../tests/language/regress/regress10204_test.dart", "../../../tests/language/regress/regress10204_test.dart",
"../../../tests/language/regress/regress10321_test.dart", "../../../tests/language/regress/regress10321_test.dart",
"../../../tests/language/regress/regress10561_test.dart",
"../../../tests/language/regress/regress10581_test.dart", "../../../tests/language/regress/regress10581_test.dart",
"../../../tests/language/regress/regress10721_test.dart", "../../../tests/language/regress/regress10721_test.dart",
"../../../tests/language/regress/regress10747_test.dart", "../../../tests/language/regress/regress10747_test.dart",
@ -5500,7 +5499,6 @@
"../../../tests/language_2/regress/r24720_test.dart", "../../../tests/language_2/regress/r24720_test.dart",
"../../../tests/language_2/regress/regress10204_test.dart", "../../../tests/language_2/regress/regress10204_test.dart",
"../../../tests/language_2/regress/regress10321_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/regress10581_test.dart",
"../../../tests/language_2/regress/regress10721_test.dart", "../../../tests/language_2/regress/regress10721_test.dart",
"../../../tests/language_2/regress/regress10747_test.dart", "../../../tests/language_2/regress/regress10747_test.dart",

View File

@ -6,7 +6,7 @@
// Verifies that class finalization doesn't crash when seeing // Verifies that class finalization doesn't crash when seeing
// superclass with type arguments which were not finalized yet. // superclass with type arguments which were not finalized yet.
abstract class GraphNode extends Comparable<dynamic> { abstract class GraphNode implements Comparable<dynamic> {
int compareTo(dynamic other) => 0; int compareTo(dynamic other) => 0;
} }

View File

@ -7,7 +7,7 @@
/// [ClosableIterator]s often use resources which should be freed after use. /// [ClosableIterator]s often use resources which should be freed after use.
/// The consumer of the iterator can either manually [close] the iterator, or /// The consumer of the iterator can either manually [close] the iterator, or
/// consume all elements on which the iterator will automatically be closed. /// consume all elements on which the iterator will automatically be closed.
abstract class ClosableIterator<T> extends Iterator<T> { abstract class ClosableIterator<T> implements Iterator<T> {
/// Close this iterator. /// Close this iterator.
void close(); void close();

View File

@ -100,7 +100,7 @@ extension JSObjectExtension on JSObject {
external void operator []=(String key, Object? value); external void operator []=(String key, Object? value);
} }
class JSArrayIteratorAdapter<T> extends Iterator<T> { class JSArrayIteratorAdapter<T> implements Iterator<T> {
final JSArray array; final JSArray array;
int index = -1; int index = -1;

View File

@ -26,8 +26,8 @@ class _SplayTreeSetNode<K> extends _SplayTreeNode<K, _SplayTreeSetNode<K>> {
/// ///
/// A [_SplayTreeNode] that also contains a value, /// A [_SplayTreeNode] that also contains a value,
/// and which implements [MapEntry]. /// and which implements [MapEntry].
class _SplayTreeMapNode<K, V> extends _SplayTreeNode<K, _SplayTreeMapNode<K, V>> class _SplayTreeMapNode<K, V>
implements MapEntry<K, V> { extends _SplayTreeNode<K, _SplayTreeMapNode<K, V>> {
final V value; final V value;
_SplayTreeMapNode(K key, this.value) : super(key); _SplayTreeMapNode(K key, this.value) : super(key);
@ -35,8 +35,6 @@ class _SplayTreeMapNode<K, V> extends _SplayTreeNode<K, _SplayTreeMapNode<K, V>>
_SplayTreeMapNode<K, V>(key, value) _SplayTreeMapNode<K, V>(key, value)
.._left = _left .._left = _left
.._right = _right; .._right = _right;
String toString() => "MapEntry($key: $value)";
} }
/// A splay tree is a self-balancing binary search tree. /// A splay tree is a self-balancing binary search tree.
@ -836,7 +834,8 @@ class _SplayTreeValueIterator<K, V>
class _SplayTreeMapEntryIterator<K, V> class _SplayTreeMapEntryIterator<K, V>
extends _SplayTreeIterator<K, _SplayTreeMapNode<K, V>, MapEntry<K, V>> { extends _SplayTreeIterator<K, _SplayTreeMapNode<K, V>, MapEntry<K, V>> {
_SplayTreeMapEntryIterator(SplayTreeMap<K, V> tree) : super(tree); _SplayTreeMapEntryIterator(SplayTreeMap<K, V> tree) : super(tree);
MapEntry<K, V> _getValue(_SplayTreeMapNode<K, V> node) => node; MapEntry<K, V> _getValue(_SplayTreeMapNode<K, V> node) =>
MapEntry<K, V>(node.key, node.value);
// Replaces the value of the current node. // Replaces the value of the current node.
void _replaceValue(V value) { void _replaceValue(V value) {

View File

@ -53,7 +53,7 @@ abstract class StringConversionSink extends ChunkedConversionSink<String> {
/// A [ClosableStringSink] extends the [StringSink] interface by adding a /// A [ClosableStringSink] extends the [StringSink] interface by adding a
/// `close` method. /// `close` method.
abstract class ClosableStringSink extends StringSink { abstract class ClosableStringSink implements StringSink {
/// Creates a new instance combining a [StringSink] [sink] and a callback /// Creates a new instance combining a [StringSink] [sink] and a callback
/// [onClose] which is invoked when the returned instance is closed. /// [onClose] which is invoked when the returned instance is closed.
factory ClosableStringSink.fromStringSink(StringSink sink, void onClose()) = factory ClosableStringSink.fromStringSink(StringSink sink, void onClose()) =

View File

@ -147,7 +147,7 @@ const Object override = _Override();
/// function `foo` is annotated with a pragma 'other-pragma' /// function `foo` is annotated with a pragma 'other-pragma'
/// specific to OtherTool. /// specific to OtherTool.
@pragma('vm:entry-point') @pragma('vm:entry-point')
class pragma { final class pragma {
/// The name of the hint. /// The name of the hint.
/// ///
/// A string that is recognized by one or more tools, or such a string prefixed /// A string that is recognized by one or more tools, or such a string prefixed

View File

@ -41,7 +41,7 @@ part of dart.core;
/// * [num]: The super class for [int] and [double]. /// * [num]: The super class for [int] and [double].
/// * [Numbers](https://dart.dev/guides/language/numbers) in /// * [Numbers](https://dart.dev/guides/language/numbers) in
/// [A tour of the Dart language](https://dart.dev/guides/language/language-tour). /// [A tour of the Dart language](https://dart.dev/guides/language/language-tour).
abstract class BigInt implements Comparable<BigInt> { abstract final class BigInt implements Comparable<BigInt> {
/// A big integer with the numerical value 0. /// A big integer with the numerical value 0.
external static BigInt get zero; external static BigInt get zero;

View File

@ -66,7 +66,7 @@ typedef Comparator<T> = int Function(T a, T b);
/// The [DateTime] class has no comparison operators, instead it has the more /// The [DateTime] class has no comparison operators, instead it has the more
/// precisely named [DateTime.isBefore] and [DateTime.isAfter], which both /// precisely named [DateTime.isBefore] and [DateTime.isAfter], which both
/// agree with [DateTime.compareTo]. /// agree with [DateTime.compareTo].
abstract class Comparable<T> { abstract interface class Comparable<T> {
/// Compares this object to another object. /// Compares this object to another object.
/// ///
/// Returns a value like a [Comparator] when comparing `this` to [other]. /// Returns a value like a [Comparator] when comparing `this` to [other].

View File

@ -596,7 +596,7 @@ class ConcurrentModificationError extends Error {
} }
/// Error that the platform can use in case of memory shortage. /// Error that the platform can use in case of memory shortage.
class OutOfMemoryError implements Error { final class OutOfMemoryError implements Error {
@pragma("vm:entry-point") @pragma("vm:entry-point")
const OutOfMemoryError(); const OutOfMemoryError();
String toString() => "Out of Memory"; String toString() => "Out of Memory";
@ -605,7 +605,7 @@ class OutOfMemoryError implements Error {
} }
/// Error that the platform can use in case of stack overflow. /// Error that the platform can use in case of stack overflow.
class StackOverflowError implements Error { final class StackOverflowError implements Error {
@pragma("vm:entry-point") @pragma("vm:entry-point")
const StackOverflowError(); const StackOverflowError();
String toString() => "Stack Overflow"; String toString() => "Stack Overflow";

View File

@ -20,7 +20,7 @@ part of dart.core;
/// For failures that are not intended to be caught, use [Error] /// For failures that are not intended to be caught, use [Error]
/// and its subclasses. /// and its subclasses.
@pragma('flutter:keep-to-string-in-subtypes') @pragma('flutter:keep-to-string-in-subtypes')
abstract class Exception { abstract interface class Exception {
factory Exception([var message]) => _Exception(message); factory Exception([var message]) => _Exception(message);
} }

View File

@ -31,7 +31,7 @@ part of dart.core;
/// **See also:** /// **See also:**
/// [Iteration](https://dart.dev/guides/libraries/library-tour#iteration) /// [Iteration](https://dart.dev/guides/libraries/library-tour#iteration)
/// in the [library tour](https://dart.dev/guides/libraries/library-tour) /// in the [library tour](https://dart.dev/guides/libraries/library-tour)
abstract class Iterator<E> { abstract interface class Iterator<E> {
/// Advances the iterator to the next element of the iteration. /// Advances the iterator to the next element of the iteration.
/// ///
/// Should be called before reading [current]. /// Should be called before reading [current].

View File

@ -468,9 +468,7 @@ abstract class Map<K, V> {
/// the `MapEntry` class will be changed to such a type, /// the `MapEntry` class will be changed to such a type,
/// and will likely no longer be able to be implemented or extended /// and will likely no longer be able to be implemented or extended
/// by classes. /// by classes.
// TODO(lrn): Make this class `final` when class modifiers are introduced. final class MapEntry<K, V> {
// Change to an `inline class` when those are available.
class MapEntry<K, V> {
/// The key of the entry. /// The key of the entry.
/// ///
/// ```dart /// ```dart

View File

@ -5,7 +5,7 @@
part of dart.core; part of dart.core;
/// An interface for basic searches within strings. /// An interface for basic searches within strings.
abstract class Pattern { abstract interface class Pattern {
/// Matches this pattern against the string repeatedly. /// Matches this pattern against the string repeatedly.
/// ///
/// If [start] is provided, matching will start at that index. /// 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` /// 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 /// object. Some patterns may never have any groups, and their matches always
/// have zero [groupCount]. /// have zero [groupCount].
abstract class Match { abstract interface class Match {
/// The index in the string where the match starts. /// The index in the string where the match starts.
int get start; int get start;

View File

@ -213,7 +213,7 @@ part of dart.core;
/// when the regexp does not find a match. /// 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) /// 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. /// exist on the internet. Use these as inspirations, too.
abstract class RegExp implements Pattern { abstract interface class RegExp implements Pattern {
/// Constructs a regular expression. /// Constructs a regular expression.
/// ///
/// Throws a [FormatException] if [source] does not follow valid regular /// Throws a [FormatException] if [source] does not follow valid regular
@ -469,7 +469,7 @@ abstract class RegExp implements Pattern {
/// } /// }
/// ``` /// ```
@Since("2.3") @Since("2.3")
abstract class RegExpMatch implements Match { abstract interface class RegExpMatch implements Match {
/// The string captured by the named capture group [name]. /// The string captured by the named capture group [name].
/// ///
/// Returns the substring of the input that the /// Returns the substring of the input that the

View File

@ -11,7 +11,7 @@ part of dart.core;
/// ///
/// These objects are created by the runtime, it is not possible to create /// These objects are created by the runtime, it is not possible to create
/// them programmatically. /// them programmatically.
abstract class StackTrace { abstract interface class StackTrace {
/// A stack trace object with no information. /// A stack trace object with no information.
/// ///
/// This stack trace is used as the default in situations where /// This stack trace is used as the default in situations where

View File

@ -4,7 +4,7 @@
part of dart.core; part of dart.core;
abstract class StringSink { abstract interface class StringSink {
/// Writes the string representation of [object]. /// Writes the string representation of [object].
/// ///
/// Converts [object] to a string using `object.toString()`. /// Converts [object] to a string using `object.toString()`.

View File

@ -30,7 +30,7 @@ part of dart.core;
/// There is no restriction on other classes, even for compile time constant /// There is no restriction on other classes, even for compile time constant
/// objects. Be careful if adding expando properties to compile time constants, /// objects. Be careful if adding expando properties to compile time constants,
/// since they will stay alive forever. /// since they will stay alive forever.
class Expando<T extends Object> { final class Expando<T extends Object> {
/// The name of the this [Expando] as passed to the constructor. /// 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. /// If no name was passed to the constructor, the value is the `null` value.
@ -123,7 +123,7 @@ class Expando<T extends Object> {
/// } /// }
/// ``` /// ```
@Since("2.17") @Since("2.17")
abstract class WeakReference<T extends Object> { abstract final class WeakReference<T extends Object> {
/// Creates a [WeakReference] pointing to the given [target]. /// Creates a [WeakReference] pointing to the given [target].
/// ///
/// The [target] must be an object supported as an [Expando] key, /// The [target] must be an object supported as an [Expando] key,
@ -220,7 +220,7 @@ abstract class WeakReference<T extends Object> {
/// function rather than a Dart function, use `dart:ffi`'s [NativeFinalizer] /// function rather than a Dart function, use `dart:ffi`'s [NativeFinalizer]
/// instead. /// instead.
@Since("2.17") @Since("2.17")
abstract class Finalizer<T> { abstract final class Finalizer<T> {
/// Creates a finalizer with the given finalization callback. /// Creates a finalizer with the given finalization callback.
/// ///
/// The [callback] is bound to the current zone /// The [callback] is bound to the current zone

View File

@ -381,7 +381,7 @@ class EfficientLengthMappedIterable<S, T> extends MappedIterable<S, T>
: super._(iterable, function); : super._(iterable, function);
} }
class MappedIterator<S, T> extends Iterator<T> { class MappedIterator<S, T> implements Iterator<T> {
T? _current; T? _current;
final Iterator<S> _iterator; final Iterator<S> _iterator;
final _Transformation<S, T> _f; final _Transformation<S, T> _f;
@ -430,7 +430,7 @@ class WhereIterable<E> extends Iterable<E> {
MappedIterable<E, T>._(this, toElement); MappedIterable<E, T>._(this, toElement);
} }
class WhereIterator<E> extends Iterator<E> { class WhereIterator<E> implements Iterator<E> {
final Iterator<E> _iterator; final Iterator<E> _iterator;
final _ElementPredicate<E> _f; final _ElementPredicate<E> _f;
@ -522,7 +522,7 @@ class EfficientLengthTakeIterable<E> extends TakeIterable<E>
} }
} }
class TakeIterator<E> extends Iterator<E> { class TakeIterator<E> implements Iterator<E> {
final Iterator<E> _iterator; final Iterator<E> _iterator;
int _remaining; int _remaining;
@ -560,7 +560,7 @@ class TakeWhileIterable<E> extends Iterable<E> {
} }
} }
class TakeWhileIterator<E> extends Iterator<E> { class TakeWhileIterator<E> implements Iterator<E> {
final Iterator<E> _iterator; final Iterator<E> _iterator;
final _ElementPredicate<E> _f; final _ElementPredicate<E> _f;
bool _isFinished = false; bool _isFinished = false;
@ -631,7 +631,7 @@ int _checkCount(int count) {
return count; return count;
} }
class SkipIterator<E> extends Iterator<E> { class SkipIterator<E> implements Iterator<E> {
final Iterator<E> _iterator; final Iterator<E> _iterator;
int _skipCount; int _skipCount;
@ -659,7 +659,7 @@ class SkipWhileIterable<E> extends Iterable<E> {
} }
} }
class SkipWhileIterator<E> extends Iterator<E> { class SkipWhileIterator<E> implements Iterator<E> {
final Iterator<E> _iterator; final Iterator<E> _iterator;
final _ElementPredicate<E> _f; final _ElementPredicate<E> _f;
bool _hasSkipped = false; bool _hasSkipped = false;

View File

@ -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()]);
}

View File

@ -8,11 +8,11 @@
import "package:expect/expect.dart"; import "package:expect/expect.dart";
import 'dart:collection'; import 'dart:collection';
class Crash extends Expando<String> { class Crash extends StringBuffer {
Crash() : super(); Crash() : super();
} }
void main() { void main() {
Crash expando = new Crash(); Crash expando = new Crash();
Expect.isTrue(expando is Expando); Expect.isTrue(expando is StringBuffer);
} }

View File

@ -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()]);
}

View File

@ -10,11 +10,11 @@
import "package:expect/expect.dart"; import "package:expect/expect.dart";
import 'dart:collection'; import 'dart:collection';
class Crash extends Expando<String> { class Crash extends StringBuffer {
Crash() : super(); Crash() : super();
} }
void main() { void main() {
Crash expando = new Crash(); Crash expando = new Crash();
Expect.isTrue(expando is Expando); Expect.isTrue(expando is StringBuffer);
} }