Skip to content

Parser allows abstract final interface class and abstract final base class declarations. #54143

Closed
@lrhn

Description

@lrhn

Example:

abstract final interface class I {}
abstract final base class B {}

base class Z extends B implements I {}

void main() {
  print(Z() is I);
  print(Z() is B);
}

Is accepted by both analyzer and CFE.

Found in dart-lang/dart_style#1319

The final and interface/base modifiers are mutually exclusive, so it should not be allowed.

It seems to require starting with abstract final. (Which is not a valid start of a variable declaration at top-level, but is locally, so it'd be reasonable to not have decided at this point whether we're starting a variable declaration or a class declaration, and then forgetting that if it is a class declaration, the we don't allow more access modifiers. But that's me guessing.)

It is, I think, the only cases that slip through, other similar declarations starting with abstract final gets disqualified for other reasons:

  • abstract final base mixin class M {} disallowed because mixins can't be final.
  • abstract final sealed class M {} disallowed because sealed classes can't be abstract.

The parser seems to react badly to abstract base interface class D {}, maybe considering it a variable named interface with a type named base, which then cannot be abstract.
That's not the best possible error message.

But this seems to be valid, so I can see why it's not easy to be the parser.

final base interface = null;
typedef base = int?;

Metadata

Metadata

Assignees

No one assigned

    Labels

    legacy-area-front-endLegacy: Use area-dart-model instead.model-parserParser issues in the analyzer/CFEtype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions