You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you have redirecting factory constructor you almost always have the same parameters as the target. It would be convenient (and less error prone) to be allowed to omit parameters to specify that the parameters are the same as the target.
Moreover this feature would have avoid a bug in the Flutter migration to nullsafety because there was a similar case where the A class was migrated as below:
Forwarding parameters with minimal syntax is a recurring request.
The proposal for enhanced default constructors (#698) spends some amount of effort generalizing over forwarding of parameters, but not in a way which then generalizes to other methods (I'm starting to think that's a negative mark against that proposal).
The same thing here ... if it only works for redirecting factory constructors, then it's probably too limited a feature.
I am trying to come up with a way to forward parameters with less syntax, for any method, but it's not trivial.
It's easier to solve for simple cases, like directly calling another function, but then it gets harder again when a function's signature starts depending on the signature of an expression in its body (we try to avoid that kind of dependencies in type inference - so, no-go for foo(*) => test ? bar(*) : baz(*); where * is derived from the signatures of bar and baz.)
(As for the flutter migration, I think a required and nullable parameter is overkill. Make it optional or make it non-nullable. Requiring you to write name: null seems weird. And I actually like that if it had been optional, it would not also have been nullable or exposed an arbitrary default value. That does make forwarding an optional parameter harder, obviously.)
When you have redirecting factory constructor you almost always have the same parameters as the target. It would be convenient (and less error prone) to be allowed to omit parameters to specify that the parameters are the same as the target.
Moreover this feature would have avoid a bug in the Flutter migration to nullsafety because there was a similar case where the A class was migrated as below:
and this code doesn't trigger any issue unless you have a call like
A(p3: null)
is your codebase.The text was updated successfully, but these errors were encountered: