Skip to content

Kernel/Fasta assumes default values are implicitly in a constant scope. #32430

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
lrhn opened this issue Mar 6, 2018 · 2 comments
Closed

Kernel/Fasta assumes default values are implicitly in a constant scope. #32430

lrhn opened this issue Mar 6, 2018 · 2 comments
Assignees
Labels
front-end-fasta front-end-kernel legacy-area-front-end Legacy: Use area-dart-model instead. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@lrhn
Copy link
Member

lrhn commented Mar 6, 2018

Dart 2 constants generally don't need to write const in front if they are in a position where they are required to be constant: initializer of const variable, sub-expression of const expression, switch case expressions.
However, one location was deliberately omitted from that list: optional parameter default values. Those should not assume that they must be const, even though they currently must. We left this open so that we can later change default value behavior and allow non-constant values without accidentally making existing code behave differently. So, you still need to write const in front of a constant expression in a default-value position.

Example:

class C {
  final x;
  const C(this.x);
}
foo([y = C([])]) => y;
main() {
  print(foo().x);
}

This code should be a compile-time error because the default value of the y parameter must be constant, and it isn't.

This currently causes the following tests to fail:

implicit_creation/implicit_const_not_default_values_test/e{1..30}

@lrhn lrhn added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) area-kernel front-end-fasta labels Mar 6, 2018
@peter-ahe-google peter-ahe-google self-assigned this Mar 6, 2018
@peter-ahe-google peter-ahe-google added the P1 A high priority bug; for example, a single project is unusable or has many test failures label Mar 6, 2018
@peter-ahe-google
Copy link
Contributor

I think this can be fixed by converting BodyBuilder.constantExpressionRequired from a bool to an enum.

@peter-ahe-google
Copy link
Contributor

Fixed in 59d8596.

@kmillikin kmillikin added legacy-area-front-end Legacy: Use area-dart-model instead. front-end-kernel and removed legacy-area-front-end Legacy: Use area-dart-model instead. labels Sep 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
front-end-fasta front-end-kernel legacy-area-front-end Legacy: Use area-dart-model instead. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants