abstract class Foo {
void bar(int x, [int y]);
}
analyzer error:
The parameter 'y' can't have a value of 'null' because of its type, so it must either be a required parameter or have a default value - line 2
Spec states:
It is an error if an optional parameter (named or otherwise) with no default value has a potentially non-nullable type except in the parameter list of an abstract method declaration.
cc @leafpetersen @rakudrama
There are additional complications, spec questions.
https://github.com/dart-lang/co19/issues/516
Analyzer should also permit optional non-nullable parameters without a default for:
external methods.native methods.These methods are like abstract methods in that they declare a method without defining one, so should be permitted to omit the default value - it is up to the external code to provide the value.
These special cases usually occur in classes that are _not_ abstract.
Handling these is required for migrating dart:html.
https://dart-review.googlesource.com/c/sdk/+/133283 will also ignore external and native methods.
Most helpful comment
https://dart-review.googlesource.com/c/sdk/+/133283 will also ignore
externalandnativemethods.