Skip to content

No error reported for overriding a method and changing an optional parameter default value #34037

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

Closed
natebosch opened this issue Jul 31, 2018 · 1 comment

Comments

@natebosch
Copy link
Member

From @eernstg on an internal thread discussing default parameter values.

That shouldn't actually happen, due to the following snippet in the spec: It is a compile-time error if an instance method $m_1$ overrides an instance member $m_2$, the signature of $m_2$ explicitly specifies a default value for a formal parameter $p$, and the signature of $m_1$ implies a different default value for $p$.

Neither the CFE produce an error or warning for this case.

class A {
  void doStuff([int a = 1]) {
    print(a);
  }
}

class B implements A {
  void doStuff([int a = 2]) {
    print(a);
  }
}

void main() {
  A().doStuff();
  B().doStuff();
}

It's likely very breaking to change the tool behavior.

cc @leafpetersen @dgrove

@leafpetersen
Copy link
Member

Duplicate of #27476 .

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

2 participants