Skip to content

Commit e293eb8

Browse files
lrhnCommit Queue
authored andcommitted
Reland "Add more interface and final modifiers to dart:core."
This is a reland of commit 4f8333e Blocked on Flutter patch: flutter/engine#40175 Original change's description: > 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> CoreLibraryReviewExempt: Accepted in original CL. Change-Id: Id713edede4228801bb097a64734be4f2187f51a9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/288206 Reviewed-by: Aske Simon Christensen <askesc@google.com> Commit-Queue: Lasse Nielsen <lrn@google.com> Reviewed-by: Nate Bosch <nbosch@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
1 parent 5ab237d commit e293eb8

39 files changed

+95
-111
lines changed

CHANGELOG.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,36 @@
6262
a shared supertype locking them to a specific name for moving backwards.
6363

6464
- **Breaking change when migrating code to Dart 3.0**:
65-
Some changes to platform libraries only affect code when it is migrated
65+
Some changes to platform libraries only affect code when that code is migrated
6666
to language version 3.0.
67-
- The `Function` type can no longer be implemented.
67+
- The `Function` type can no longer be implemented, extended or mixed in.
6868
Since Dart 2.0 writing `implements Function` has been allowed
6969
for backwards compatibility, but it has not had any effect.
70-
In Dart 3.0, the `Function` type is `final` and cannot be implemented
71-
by class-modifier aware code.
70+
In Dart 3.0, the `Function` type is `final` and cannot be subtyped,
71+
preventing code from mistakenly assuming it works.
72+
- The following declarations can only be implemented, not extended:
73+
* `Comparable`
74+
* `Exception`
75+
* `Iterator`
76+
* `Pattern`
77+
* `Match`
78+
* `RegExp`
79+
* `RegExpMatch`
80+
* `StackTrace`
81+
* `StringSink`
82+
None of these declarations contained any implementation to inherit,
83+
and are marked as `interface` to signify that they are only intended
84+
as interfaces.
85+
- The following declarations can no longer be implemented or extended:
86+
* `MapEntry`
87+
* `OutOfMemoryError`
88+
* `StackOverflowError`
89+
* `Expando`
90+
* `WeakReference`
91+
* `Finalizer`
92+
The `MapEntry` value class is restricted to enable later optimizations.
93+
The remaining classes are tightly coupled to the platform and not
94+
intended to be subclassed or implemented.
7295

7396
[#49529]: https://github.com/dart-lang/sdk/issues/49529
7497
[`List.filled`]: https://api.dart.dev/stable/2.18.6/dart-core/List/List.filled.html

pkg/_fe_analyzer_shared/lib/src/util/link_implementation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class LinkIterator<T> implements Iterator<T> {
3131

3232
typedef T Transformation<S, T>(S input);
3333

34-
class MappedLinkIterator<S, T> extends Iterator<T> {
34+
class MappedLinkIterator<S, T> implements Iterator<T> {
3535
Transformation<S, T> _transformation;
3636
Link<S> _link;
3737
T? _current;

pkg/compiler/lib/src/universe/class_set.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ class SubtypesIterable extends IterableBase<ClassEntity> {
967967
}
968968

969969
/// Iterator for the subtypes in a [ClassSet].
970-
class SubtypesIterator extends Iterator<ClassEntity> {
970+
class SubtypesIterator implements Iterator<ClassEntity> {
971971
final SubtypesIterable iterable;
972972
Iterator<ClassEntity>? elements;
973973
Iterator<ClassHierarchyNode>? hierarchyNodes;

pkg/compiler/test/inference/powerset_bits3_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ import '../helpers/element_lookup.dart';
1313
import 'package:compiler/src/util/memory_compiler.dart';
1414

1515
const String CODE = """
16-
class A extends Comparable {
16+
class A implements Comparable {
1717
int compareTo(x) { return 0; }
1818
}
19-
class B extends Comparable {
19+
class B implements Comparable {
2020
int compareTo(x) { return 0; }
2121
}
22-
class C extends Comparable {
22+
class C implements Comparable {
2323
int compareTo(x) { return 0; }
2424
}
25-
class D extends Comparable {
25+
class D implements Comparable {
2626
int compareTo(x) { return 0; }
2727
}
28-
class E extends Comparable {
28+
class E implements Comparable {
2929
int compareTo(x) { return 0; }
3030
}
3131

pkg/front_end/testcases/incremental/issue_32366.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ worlds:
88
- entry: main.dart
99
sources:
1010
main.dart: |
11-
abstract class AIterator extends Iterator {
11+
abstract class AIterator implements Iterator {
1212
}
1313
class Foo {
1414
final a;
@@ -25,7 +25,7 @@ worlds:
2525
errors: true
2626
sources:
2727
main.dart: |
28-
abstract class BIterator extends Iterator {
28+
abstract class BIterator implements Iterator {
2929
}
3030
class Foo {
3131
final a kjsdf ksjdf ;

pkg/front_end/testcases/incremental/issue_32366.yaml.world.1.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
main = main::main;
22
library from "org-dartlang-test:///main.dart" as main {
33

4-
abstract class AIterator extends dart.core::Iterator<dynamic> {
4+
abstract class AIterator extends dart.core::Object implements dart.core::Iterator<dynamic> {
55
synthetic constructor •() → main::AIterator
6-
: super dart.core::Iterator::•()
6+
: super dart.core::Object::•()
77
;
88
}
99
class Foo extends dart.core::Object {

pkg/front_end/testcases/incremental/issue_32366.yaml.world.2.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ library from "org-dartlang-test:///main.dart" as main {
3030
// ^
3131
//
3232

33-
abstract class BIterator extends dart.core::Iterator<dynamic> {
33+
abstract class BIterator extends dart.core::Object implements dart.core::Iterator<dynamic> {
3434
synthetic constructor •() → main::BIterator
35-
: super dart.core::Iterator::•()
35+
: super dart.core::Object::•()
3636
;
3737
}
3838
class Foo extends dart.core::Object {

pkg/front_end/testcases/inference/try_catch_promotion.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class C {}
1111

1212
class D extends C {}
1313

14-
class E extends StackTrace {}
14+
class E implements StackTrace {}
1515

1616
void test(void f()) {
1717
try {

pkg/front_end/testcases/inference/try_catch_promotion.dart.strong.expect

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ class D extends self::C {
2929
: super self::C::•()
3030
;
3131
}
32-
class E extends core::StackTrace {
32+
class E extends core::Object implements core::StackTrace {
3333
synthetic constructor •() → self::E*
34-
: super core::StackTrace::•()
34+
: super core::Object::•()
3535
;
3636
abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod
37-
abstract member-signature method toString() → core::String*; -> core::StackTrace::toString
3837
abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode
3938
abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
4039
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf
4140
abstract member-signature method _simpleInstanceOfTrue(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfTrue
4241
abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
4342
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
4443
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode
44+
abstract member-signature method toString() → core::String*; -> core::Object::toString
4545
abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
4646
}
4747
static method test(() →* void f) → void {

pkg/front_end/testcases/inference/try_catch_promotion.dart.strong.transformed.expect

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ class D extends self::C {
2929
: super self::C::•()
3030
;
3131
}
32-
class E extends core::StackTrace {
32+
class E extends core::Object implements core::StackTrace {
3333
synthetic constructor •() → self::E*
34-
: super core::StackTrace::•()
34+
: super core::Object::•()
3535
;
3636
abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod
37-
abstract member-signature method toString() → core::String*; -> core::StackTrace::toString
3837
abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode
3938
abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
4039
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf
4140
abstract member-signature method _simpleInstanceOfTrue(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfTrue
4241
abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
4342
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
4443
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode
44+
abstract member-signature method toString() → core::String*; -> core::Object::toString
4545
abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
4646
}
4747
static method test(() →* void f) → void {

0 commit comments

Comments
 (0)