dart-lang / language

Design of the Dart language
Other
2.65k stars 201 forks source link

Make default values of parameters parts of function type #3209

Open Cat-sushi opened 1 year ago

Cat-sushi commented 1 year ago

Removal or change of default values is almost always breaking. The solo exception is removal of default null from nullable parameters. So, I think default values of parameters should be parts of function types, to be checked by the compiler.

cf. #3206

lrhn commented 1 year ago

That would require type checking to compare values. Those would presumably be constant values only, but I'm sure it will give new and exciting challenges.

Is a function type with no default value a supertype of a function type with a default value? Or subtype? Or can it even exist.

void Function([int x]) f = ([int x = 0]) {}; // Allowed or not?

I pretty sure the inconvenience and complexity is not worth the gain.

rrousselGit commented 1 year ago
void Function([int x]) f = ([int x = 0]) {}; //

If that doesn't work anymore, that'd be a significant breaking change.

Freezed relies on a sentinel default value for supporting copyWith(a: null):

Obj copyWith({MyClass x}) => ({Object x = _sentinel} ) {...}