diff --git a/working/3102 - implied-name/feature-specification.md b/working/3102 - implied-name/feature-specification.md new file mode 100644 index 000000000..9ba3d9cbc --- /dev/null +++ b/working/3102 - implied-name/feature-specification.md @@ -0,0 +1,374 @@ +# Dart Implied Parameter/Record Field Names + +Author: lrn@google.com
+Version: 1.0 + +## Pitch +Writing the same name twice is annoying. That happens often when forwarding +named arguments: +```dart + var subscription = stream.listen( + onData, + onError: onError, + onDone: onDone, + cancelOnError: cancelOnError, + ); +``` + +To avoid redundant repetition, this feature will allow you to omit the +argument name if it's the same name as the expression providing the value. + +```dart + var subscription = stream.listen( + onData, + :onError, + :onDone, + :cancelOnError, + ); +``` + +Same applies to record literal fields, where we have nice syntax +for destructuring, but not for re-creating: +```dart +typedef Color = ({int red, int green, int blue, int alpha}); + +Color colorWithAlpha(Color color, int newAlpha) { + var (:red, :green, :blue, alpha: _) = color; + return (red: red, green: green, blue: blue, alpha: newAlpha); +} +``` +which this feature will allow to be written as: +```dart +Color colorWithAlpha(Color color, int alpha) { + var (:red, :green, :blue, alpha: _) = color; + return (:red, :green, :blue, :alpha); +} +``` + +## Specification + +The current grammar for a named argument is: +```ebnf + ::=