Skip to content

[analyzer] No error produced for not-implementing-final-classes through legacy libraries. #52078

Description

@lrhn

Example:

// old_lib.dart
// @dart=2.19

// MapEntry is `final`, but can be implemented due to SDK exception.
class M implements MapEntry<int, int> {
  int get key => 0;
  int get value => 1;
  String toString() => "Bad";
}

and

// new_lib.dart
// @dart=3.0

import "old_lib.dart";

class N implements M {
  int get key => 0;
  int get value => 1;
  String toString() => "Evil";
}

void main() {
  print(N()); // Evil.
}

This gives no errors, or warnings, in the front end or analyzer.

According to specification, you are not allowed to implement any interface which has any superinterface whose declaration is marked base or final. (Unless you are, yourself, a pre-feature library and all such superinterfaces are in platform libraries.)

Here N is not in a pre-feature library, so it gets no exemptions.
M has a superinterface marked final, so it must not be implemented by N.

(We don't have a rule against N extending M, so its not like we can prevent everything, but we can prevent new implements of a final platform type in 3.0-libraries.)

Filing as area-fe-analyzer-shared. Split this into two issues if it's two different bugs.

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work ondart-model-analyzer-specIssues with the analyzer's implementation of the language speclegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions