Skip to content

Commit 98de36b

Browse files
authored
[class mod] Clarify how language versioning affects modifiers. (#2728)
* [class mod] Clarify how language versioning affects modifiers. Fix #2725. * Add TODO.
1 parent eb985e7 commit 98de36b

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

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

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Author: Bob Nystrom
44

55
Status: Accepted
66

7-
Version 1.1
7+
Version 1.2
88

99
Experiment flag: class-modifiers
1010

@@ -599,18 +599,40 @@ non-breaking.
599599

600600
Let `n` be the language version this proposal ships in. Then:
601601

602+
* `base`, `interface`, `final`, and `mixin` can only be applied to classes and
603+
mixins in libraries whose language version is `>= n`.
604+
605+
* When the `base`, `interface`, `final`, `mixin`, or `sealed` modifiers are
606+
placed on a class or mixin, the resulting restrictions apply to all other
607+
libraries, even libraries whose version is `< n`.
608+
609+
*In other words, we gate being able to _author_ the restrictions to
610+
libraries on version `n`. But once a type has those restrictions, they apply
611+
to all other libraries, regardless of the versions of those libraries.
612+
"Ignorance of the law is no defense."*
613+
614+
**TODO:** Decide if we want to carve out an exception to this rule for the
615+
SDK core libraries.
616+
602617
* A class declaration in a library whose language version is `< n` can be used
603-
as a mixin as long as the class meets the mixin restrictions. *This is is
618+
as a mixin as long as the class meets the mixin restrictions. This is is
604619
true even if the library where the class is being used as a mixin is `>=
605-
n`.*
620+
n`.
621+
622+
*For libraries whose version is `< n`, we can't tell if the intent of
623+
`class` was "just a class" or "both a class and a mixin". For compatibility,
624+
we assume the latter, even if the class is being used as a mixin in a
625+
library whose version is `>= n` and where it does happen to be possible to
626+
distinguish those two intents.*
606627

607628
* A class declaration in a library whose version is `>= n` must be explicitly
608-
marked `mixin class` to allow the class to be used in a `with` clause. *This
609-
is true even if the library where the class is being used as a mixin is `<
610-
n`.*
629+
marked `mixin class` to allow the class to be used as a mixin. This is true
630+
even if the library where the class is being used as a mixin is `< n`.
611631

612-
* The `base`, `interface`, and `final` modifiers on classes and mixins can
613-
only be used in libraries whose language version is `>= n`.
632+
*When a class is in a library where it possible to distinguish between
633+
whether the class is intended to use it as a mixin or not, the author is
634+
obliged to, and that intent applies to all other libraries regardless of
635+
their version.*
614636

615637
### Compatibility
616638

@@ -622,6 +644,10 @@ needed.
622644

623645
## Changelog
624646

647+
1.2
648+
649+
- Specify how all modifiers interact with language versioning (#2725).
650+
625651
1.1
626652

627653
- Clarify that all modifiers are gated behind a language version.

0 commit comments

Comments
 (0)