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
And in my buisness logic I want to update each element of the class at different times and in an unknown order (e.g with user input). As the properties are final, each time I have to create a new product with the other, unedited, fields saved fed back into the class
Lets say in an anonymous function associated with the user inputting the id.
I see no reason why this shouldn't be possible. If a positional argument is mandatory (it is by definition) and the class is given (it is) then there is no reason why it would be error prone to access the properties of the positional argument in the definitions of the optional argument(s).
Current errors:
The default value of an optional parameter must be constant.dart(non_constant_default_value)
Undefined name 'productToEdit'.
Try correcting the name to one that is defined, or defining the name.
Proposed Fix:
To allow the use of non-constant positional arguments
(If required) to bring the name definition of madatory parameters forward in time to always predate the definition of optional parameters so it is in memory and ready to use.
HarvsG
changed the title
Allow optional defaults to be properties of manadtory positional parameters
Allow optional defaults to be properties of mandatory positional parameters
May 4, 2020
Thanks @eernstg, that is helpful. I think the change in #140 is necessary for this solution but may not be sufficient. As the second error that is given is:
Undefined name 'productToEdit'.
Try correcting the name to one that is defined, or defining the name.
Proposed fix 2:
(May already be the case) to bring the name definition of madatory parameters forward in time to always predate the definition of optional parameters so it is in memory and ready to use.
@HarvsG, that's a matter of scoping: If we change parameter default values such that they can be expressions in a more general sense (rather than being constant expressions), there will be more declarations that can be in scope. In particular, we could allow default value expressions to refer to other parameters (as in your example).
However, we probably don't want to require that implementations must solve any recursive equations, or that they must run iterations until a fixed point is reached. We never promise that static analysis will detect non-termination, but we might want to prevent things like void foo([int x = y + 1, int y = x + 1]). So we might choose to prevent any references to parameters, or at least enforce that the dependency graph has no cycles.
Describe the new syntax or language feature you'd like to see incorporated into
Dart. Ideally you can relate this to a
request
issue filed separately.let's say I have some class:
And in my buisness logic I want to update each element of the class at different times and in an unknown order (e.g with user input). As the properties are final, each time I have to create a new product with the other, unedited, fields saved fed back into the class
Lets say in an anonymous function associated with the user inputting the id.
If I wanted to do the same with the other fields, I could write
And so on...
This leads to a lot of duplicated code.
It would be great if I could define a function like this:
Then to update any one paremeter I could simply run:
I see no reason why this shouldn't be possible. If a positional argument is mandatory (it is by definition) and the class is given (it is) then there is no reason why it would be error prone to access the properties of the positional argument in the definitions of the optional argument(s).
Current errors:
Proposed Fix:
A workaround is to do something like:
Which could then be called as:
The text was updated successfully, but these errors were encountered: