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
I'm curious why const values are required. I think it would be better if this requirement will be lowering a bit. It'll be awesome to be able to use previous passed arguments as default parameters or every time create a new modifiable default list in place of using const one:
It would be nice if an omitted parameter forced a computation instead of just inserting a constant value.
However, that comes with some complication too. The computation needs to have a scope (can it only see previous parameters? What if they are named parameters, which one are "previous" then? Is it just source order?). They will be executed at a point where you cannot be inside a try/catch, so there is no way to catch errors. You can tell whether a parameter was passed or not by having side effects:
abstractclassFoo {
intfoo(int x, {int y});
}
class_SmartFooimplementsFoo {
static _yWasOmitted =false;
intfoo(int x, {int y = ($yWasOmitted =true) ?0:throw"unreachable"}) {
if (_yWasOmitted) {
_yWasOmitted =false;
// do something special
}
}
}
That's something we currently do not allow, you cannot detect a difference between passing the default value directly or not passing anything. The ability to do that is problematic for methods that forward invocations.
So, to have this feature, I'd prefer if you couldn't tell the difference between omitting an optional parameter and explicitly passing null, and then binding the parameter to the default value would effectively be computed as parameter = argument ?? defaultExpression.
Documentation says that
I'm curious why
const
values are required. I think it would be better if this requirement will be lowering a bit. It'll be awesome to be able to use previous passed arguments as default parameters or every time create a new modifiable default list in place of usingconst
one:The text was updated successfully, but these errors were encountered: