For brevity, allow redirecting factory constructors to omit the formal parameter list #4135
Labels
brevity
A feature whose purpose is to enable concise syntax, typically expressible already in a longer form
enhanced-syntax
Used with proposals about improvements of the Dart grammar
small-feature
A small feature which is relatively cheap to implement.
This is a proposal that allows some constructor declarations to be less verbose.
The formal parameter list of a redirecting factory constructor has a certain amount of expressive power: It is possible to declare a stronger type constraint on each parameter than the corresponding parameter type in the redirectee. However, in the (very typical) case where the parameter types are the same, it is possible to compute the parameter list of this kind of constructor based solely on the redirectee.
This means that we could allow the formal parameter list to be omitted, in which case the formal parameter list would be implicitly induced, using the same parameter type for every parameter as in the redirectee.
The code would not be significantly harder to read: Documentation for a redirecting factory constructor that omits the formal parameter list could show the formal parameter list which is implicitly induced, and IDEs could show it when a mouse pointer is hovering over the constructor name.
Here is an example which is a variant of something that came out of discussions about
.identifier
shorthands (#357). The example is relevant simply because it declares several redirecting factory constructors.With the abbreviation which is proposed here, it would look as follows:
Come to think of it, we could also allow the class name to be omitted. See #4144.
The text was updated successfully, but these errors were encountered: