-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Redirecting factory tear-off type error. #53837
Comments
See also dart-lang/language#3427. I think we might be better off by just dropping the forwarder and evaluating |
I disagree with providing direct access to a potentially private constructor without limiting the possible arguments. |
That is a very strong argument, and I'd like to have that encapsulation as well. However, we might need some new language concepts in order to be able to support this. |
We may only need to allow the synthetic tear-off function is allowed to have a default value which is not a subtype of the parameter type. It does mean that we can't use the normal "binding arguments to formals" algorithm when calling it. We could directly say what its behavior is, when called with an argument list. Which we need to do anyway, if it can't be a desugaring to Dart code. As long as it means that |
Exactly: We need to take the new (currently unsupported) semantics into account as a full-fledged part of the language (that is, it must be well-defined and well-understood). We may then use this new semantics in just the situations where we must use it (that is, we may not provide access to the new semantics using any syntax that developers can write), and then in the future we may still choose to generalize the mechanism and provide access to it using some syntactic form. To me it sounds like the core of a function forwarding semantics. |
If a redirecting factory constructor redirects to a constructor with a wider parameter type for an optional parameter, and which has a default value in that wider parameter type, then the constructor tear-off seems to get that default value as its own default value, and when it gets type-checked, that becomes an error.
It should likely not be type-checked.
Example:
Here Dart2JS (dartpad.dev, master branch) prints:
VM has no issue.
This may be due to the tear-off lowering introduced by the front-end. The result of that lowering is not a valid Dart function declaration, and must therefore be treated specially by the compiler (by not checking the default value against the parameter type, which is safe because it's definitely forwarding to a constructor which will accept the value).
It is very likely also be an issue in the constructor-tear-off specification, where it says that the tear-off is equivalent to tearing off a static function with the same parameters and default values. That does not account for forwarding factory constructors not having default values of their own, and their target not necessarily having a default value mathcing the parameter type.
Even if the spec has an issue, the desired behavior is that of the VM, which means that tearing off a forwarding factory constrcuctor cannot be expressed as a pure desugaring to tearing off a static function.
That is, use the following instead:
(And we likely need to make sure that the implicit generic function instantiation coercion is also defined in terms of forwarding the argument list, not copying default values, since it applies to the constructor tear-off of generic classes, including forwarding factory tear-offs.)
We really should get out of the habit of defining things in terms of desugarings. It keeps having unintended side-effects.
The text was updated successfully, but these errors were encountered: