Skip to content

Commit fd8d98c

Browse files
authored
Add an error for on F where F is final and outside the current library (#3027)
Add an error to the class modifiers feature specification for `on F`, where `F` is final and declared outside the current library.
1 parent f58f8c5 commit fd8d98c

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

accepted/future-releases/class-modifiers/feature-specification.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -687,34 +687,56 @@ It's a compile-time error if:
687687
class M with S {} // Error, for several reasons.
688688
```
689689
690-
* A class extends or mixes in a declaration marked `interface` or `final`
690+
* A declaration has a direct super declaration from another library
691+
which is marked `final`_(with some exceptions for platform libraries)_.
692+
693+
More formally:
694+
A declaration *D* from library *L* has a direct superdeclaration *S*
695+
marked `final` (so necessarily a `class` declaration) in library *K*, and neither
696+
* *L* and *K* is the same library, nor
697+
* *K* is a platform library and *L* is a pre-feature library.
698+
699+
```dart
700+
// a.dart
701+
final class F {}
702+
703+
// b.dart
704+
import 'a.dart';
705+
706+
class C1 extends F {} // Error.
707+
class C2 implements F {} // Error.
708+
mixin class C3 implements F {} // Error.
709+
mixin M1 implements F {} // Error.
710+
mixin M2 on F {} // Error.
711+
enum E1 implements F {} // Error.
712+
```
713+
714+
* A class extends or mixes in a declaration marked `interface`
691715
from another library _(with some exceptions for platform libraries)_.
692716
693717
_(You cannot inherit implementation from a class marked `interface`
694-
or `final` except inside the same library. Unless you are in a
695-
pre-feature library and you are inheriting from a platform library.)_
718+
except inside the same library. Unless you are in a pre-feature
719+
library and you are inheriting from a platform library.)_
696720
697721
More formally:
698-
A declaration *C* from library *L* has a declared superclass or mixin
699-
declaration *S* marked `interface` or `final` from library *K*, and neither
722+
A declaration *C* from library *L* has a declared superclass
723+
declaration *S* marked `interface` from library *K*, and neither
700724
* *L* and *K* is the same library, nor
701725
* *K* is a platform library and *L* is a pre-feature library.
702726
703727
```dart
704728
// a.dart
705729
interface class I {}
706-
final class F {}
707730
708731
// b.dart
709732
import 'a.dart';
710733
711734
class C1 extends I {} // Error.
712-
class C2 extends F {} // Error.
713735
```
714736
715737
* A declaration implements another declaration, and the other
716-
declaration itself, or any of its super-declarations,
717-
are marked `base` or `final` and are not from the first declaration's
738+
declaration itself, or any of its super-declarations, are marked
739+
`base` or `final` and are not from the first declaration's
718740
library _(with some exceptions for platform libraries)_.
719741
720742
_(You can only implement an interface if *all* `base` or `final`
@@ -724,8 +746,8 @@ It's a compile-time error if:
724746
725747
More formally:
726748
A declaration *C* in library *L* has a declared interface *P*,
727-
and *P* has any superdeclaration *S*, from a library *K*,
728-
which is marked `base` or `final` _(including *S* being *P* itself)_,
749+
and *P* has any superdeclaration *S*, from a library *K*, which
750+
is marked `base` or `final` _(including *S* being *P* itself)_,
729751
and neither:
730752
* *K* and *L* is the same library, mor
731753
* *K* is a platform library and *L* is a pre-feature library.
@@ -850,10 +872,10 @@ mixin class C {
850872
C(int x); // Error.
851873
C(this.x); // Error.
852874
C() {} // Error.
853-
C(): x = 0;
875+
C(): x = 0; // Error.
854876
C(): assert(true); // Error.
855877
C(): super(); // Error.
856-
C(): this.named();
878+
C(): this.named(); // Error.
857879
858880
// Not generative constructors, so neither trivial generative nor non-trivial
859881
// generative:

0 commit comments

Comments
 (0)