Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Make @override a keyword #60392

Closed
tolotrasamuel opened this issue Mar 25, 2025 · 2 comments
Closed

[Proposal] Make @override a keyword #60392

tolotrasamuel opened this issue Mar 25, 2025 · 2 comments

Comments

@tolotrasamuel
Copy link

tolotrasamuel commented Mar 25, 2025

Motivation:

Here’s the scenario:

  1. We have a Weapon class with a method isMassDestruction() that returns false by default. The subclass NuclearBomb overrides this method to return true.
  2. During a refactor, the method isMassDestruction() was renamed to isDestructive() in the Weapon class.
  3. We updated the method in NuclearBomb, but we missed the override_on_non_overriding_member warning, as it was just one of 3,737 warnings and 1777 hints. (we have lots of auto generated code)
  4. The method in NuclearBomb wasn’t updated to the new name, and, there were not analyzer error, the bug reached production, it caused a critical bug, leading to a nuclear bomb explosion in the app.

Here's the code:

class Weapon {
  bool isMassDestruction() {
    return false;
  }
}

class NuclearBomb extends Weapon {
  @override
  bool isMassDestruction() {
    return true;
  }
}

After the refactor, the code became:

class Weapon {
  bool isDestructive() {
    return false;
  }
}

class NuclearBomb extends Weapon {
  @override
  bool isMassDestruction() {
    return true;  // This is the old method name, which wasn't updated
  }
}

Discussion

One may argue that the developer should do the shore of cleaning up warnings and info. And Yes, there is already a way to turn the linter rule into an error with following:

linter:
  rules:
    override_on_non_overriding_member: true

analyzer:
    errors:
      override_on_non_overriding_member: error

However, having override_on_non_overriding_member flag raised, wether it be an error, warning or info in almost all case suggest a bug. Therefore, I believe it should be turned into a keyword. And prevent the application from compiling if the rule is raised. (much like how @required once was not a keyword)

Many programming language already behave as per the proposal.

@tolotrasamuel tolotrasamuel changed the title [Proposal] Make override a keyword [Proposal] Make @override a keyword Mar 25, 2025
@FMorschel
Copy link
Contributor

CC @lrhn

@mraleph
Copy link
Member

mraleph commented Mar 25, 2025

Duplicate of dart-lang/language#1610

@mraleph mraleph marked this as a duplicate of dart-lang/language#1610 Mar 25, 2025
@mraleph mraleph closed this as completed Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants