Kernel/Fasta assumes default values are implicitly in a constant scope. #32430
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)
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:
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:
The text was updated successfully, but these errors were encountered: