Skip to content

[Class Modifiers] Why do we propagate base through implements edges. #2909

Closed
@leafpetersen

Description

@leafpetersen

In the section on transitive restrictions, the class modifiers proposal says the following:

This proposal takes the last option where types have exactly the restrictions they declare but a lint can be turned on for users who want to be reminded if they re-add a capability in a subtype.

The subsequent section on "Inherited restrictions" motivates preventing re-adding capabilities to classes from other libraries, but is silent on the question of re-adding capabilities to classes in the same library.

Nonetheless, the section on disallowing implementation chooses to disallow some (but not all) capabilities to be re-added to classes in the same library. For example:

final class Vehicle {}

class LandVehicle implements Vehicle {}
class AquaticVehicle implements Vehicle {}
class FlyingVehicle implements Vehicle {}

The motivation I've heard for the core restriction is that we wish to allow a user to write a class for which all subtypes are guaranteed to inherit from (and consequently call the constructor of) the original super type. But of course, this is not true - the example above is legal if I add base to the three subtypes, and yet there are still instances of Vehicle that neither inherit from Vehicle nor call its constructor.

Why do we choose to propagate the base restriction over implements edges? This seems under motivated to me, and would seem to disallow useful patterns.

cc @dart-lang/language-team

Metadata

Metadata

Assignees

No one assigned

    Labels

    class-modifiersIssues related to "base", "final", "interface", and "mixin" modifiers on classes and mixins.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions