Skip to content

Commit e9b2fc0

Browse files
committed
[Modules] Use language versioning to not break existing classes.
1 parent 3474ac4 commit e9b2fc0

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

working/modules/feature-specification.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,29 @@ inadvertently break a capability that the type offers.
258258
### Capabilities on legacy classes
259259

260260
The above syntax means that it an error to implement, mixin, or extend a class
261-
declared just using `class`. This would break nearly all existing Dart code.
262-
To avoid that, we specify that Dart classes that are not in modules are
263-
implicitly treated as if they were declared as `open interface mixin class`.
261+
declared just using `class`. This would break nearly all existing Dart code if
262+
it were retroactively applied to existing code.
263+
264+
Fortunately, we have [language versioning][] to help. Dart libraries still at
265+
the language version before modules will behave as if all class declarations
266+
are implicitly marked with all of the capabilities the class can support. In
267+
particular:
268+
269+
* All classes are treated as implicitly marked `interface`.
270+
271+
* If the class has at least one generative constructor (which may be default)
272+
and is not marked `abstract` it is treated as implicitly marked `open`.
273+
274+
* If the class has no constructors, it is treated as implicitly marked
275+
`mixin`.
276+
277+
[language versioning]: https://dart.dev/guides/language/evolution#language-versioning
278+
279+
When updating a library to the language version that supports modules, you'll
280+
want to decide what capabilities to offer, or just place all the modifiers you
281+
can to preserve the class's current behavior.
282+
283+
**TODO: Investigate tooling to automatically migrate.**
264284

265285
## Capability controls on members
266286

0 commit comments

Comments
 (0)