Closed
Description
We need to resolve how default parameter values should work with NNBD, for both nullably and non-nullably typed parameters.
Consider:
void f({int x; int? y}) {...}
void g({int x = 0; int? y = 1}) { }
Questions:
- Is the declaration of
x
inf
an error?- If not, then
x
is effectively required- This in turn means that if the type of
f
is a subtype of the type ofg
, then thex
parameter ofg
must also be treated as required, which means there's no point in giving it a default. - So this effectively means that there are no optional non-nullable variables
- Unless we separately added the notion of required named parameters that are part of the type
- This in turn means that if the type of
- If so, then optional non-nullable parameters must always have a default value
- If not, then
- Is passing
null
to thex
parameter ofg
allowed (and interpreted the same as not passing anything)?- If so, then behaviorally, what's the difference between
void Function({int x})
andvoid Function({int? x})
? You can passnull
to both of them.
- If so, then behaviorally, what's the difference between
- Does passing
null
to they
argument ofg
bindy
tonull
(current behavior) or to1
.- Changing this would be a breaking change.
- This change has been advocated for independently, since it makes forwarding work better.