-
Notifications
You must be signed in to change notification settings - Fork 165
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
undefined can't be a member of a union type #962
Comments
It might work to make undefined distinguishable from all other types. |
cc @tabatkins |
Oooh, I didn't realize additional spec work had to be done there. Yes, both of these changes are reasonable, I'll write a PR. |
Looking over the remaining spots where
So this implies that the current behavior is that a JS (Also, hm, all of the 3.2.24 algo confuses me, since it's composed of nested conditionals where the inner conditionals don't have "else" clauses. Is the implication that you continue to next top-level step if you fail all the conditions?) |
… undefined specially. Fixes whatwg#962.
It might be okay for them to be distinguishable in theory, but I don't think we'd ever want to have APIs use that. And yeah, if the algorithm doesn't return, it continues, ultimately throwing. |
When converting from ES to IDL union there should never be undefined in the union, since IDL undefined is forbidden in arguments and in dictionaries? At least that's how I read "undefined must not be used as the type of an argument in any circumstance …, or as the type of a dictionary member". |
I would err on the side of them not being distinguishable. |
Yes, it's forbidden only in those places. It's allowed in return types, attribute types, etc. (And it's only forbidden in those places because we have
Works for me. I've edited the distinguishability table, and that means I can still add a rule checking for undefined in the union. New question now that I've reviewing more here - currently, the spec says that So, per current spec, you can satisfy an IDL But the opposite is not true - you can't satisfy a IDL (This didn't come up in the previous |
Hm, no, dictionary types are explicitly excluded from being nullable, so undefined should be too. |
Okay, chasing the blame backwards, dictionary types are excluded from nullability specifically because the spec has always considered JS But I don't want that to be the case for Or do we want to maintain the old IDL idea that JS's |
I think it makes sense for (It might make even more sense if |
Yeah, this accords with my preference as well. I'll need to do a more thoro eye-check to make sure that nullable and dictionary types are defined to play well with the |
I had totally missed that writable attributes can take undefined in a union. What would be the use for undefined being nullable? I don't think that would make a lot of sense outside of unions. I like |
Thanks, I guess it should be a shorthand for |
If you insert a rule at the top of the union conversion that |
Yeah, planning to let an explicit |
Okay, #965 should close this now. |
I think one of the goals of #60 was to allow union types with undefined as a member type for return values. It did so by just adding undefined to the grammar for Type. Union types currently require member types to be distinguishable (Each pair of flattened member types in a union type, T and U, must be distinguishable). I don't see any changes to that in #906, or any changes to add rules for undefined in the distinguishability algorithm, so right now undefined cannot actually be a member type of a union type.
The prose for union type conversion to an ECMAScript value also still contains the following sentence: If the value is an object reference to a special object that represents an ECMAScript undefined value, then it is converted to the ECMAScript undefined value. I'm not sure we should keep that, there is a rule for conversion of the undefined type, so it should be possible to rely on the generic algorithm there.
The text was updated successfully, but these errors were encountered: