From bc6db3fc7dd096189c1682fff66c13eb106f493e Mon Sep 17 00:00:00 2001 From: "Lasse R.H. Nielsen" Date: Thu, 16 Oct 2025 14:50:52 +0200 Subject: [PATCH 1/2] Add proposed feature specification for "implicit names". --- .../feature-specification.md | 259 ++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 working/3102 - implied-name/feature-specification.md diff --git a/working/3102 - implied-name/feature-specification.md b/working/3102 - implied-name/feature-specification.md new file mode 100644 index 000000000..1e8bd07f3 --- /dev/null +++ b/working/3102 - implied-name/feature-specification.md @@ -0,0 +1,259 @@ +# 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, Dart will allow you to omit the +argument name if it's the same name as 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}); +extension on Color { + Color withAlpha(int alpha) { + var (:red, :green, :blue, alpha: _) = this; + return (red: red, green: green, blue: blue, alpha: alpha); + } +} +``` +will become +```dart +extension on Color { + Color withAlpha(int alpha) { + var (:red, :green, :blue, alpha: _) = this; + return (:red, :green, :blue, :alpha); + } +} +``` + +## Specification + +The current grammar for a named argument is: +```ebnf + ::=