-
Notifications
You must be signed in to change notification settings - Fork 213
For brevity, allow redirecting factory constructors to omit the formal parameter list #4135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I tried to do this yesterday and was surprised that it doesn't just work. |
I'm not usually a fan of omitting and inferring names, but since the "body" of a redirecting factory constructor cannot reference the parameters by name anyway, it's probably safe. The names might be copied for documentation purposes. Or not. I'd probably say that from the language's perspective, the positional parameters would be unnamed. If DartDoc or the analyzer wants to do something more, to help people, they can copy the names from the target constructor. The grammar is trivial, it's just making the parameter list optional. If what follows the (Could also allow a redirecting factory constructor to have a parameter list, and omit the types.) |
(Good point! That would be very much in line with the treatment of parameter declarations in instance methods during override inference.) |
note: this is almost possible by just doing what this means is: an alternative solution to this problem is to instead allow const-returning functions - for now limited to const constructors.
just spitballing here. there's probably an associated issue it can go to, but I thought i'd mention it. |
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: