-
Notifications
You must be signed in to change notification settings - Fork 164
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
Dictionary types being nullable doesn't make sense #967
Comments
I think this might be a thing some people do with nested dictionaries. Or perhaps return values? (I agree with you that it's a bad pattern.) |
Do we currently have a use for nested nullable dictionaries? |
I'm not sure. There is some related discussion in #76 and one thing bz mentions there that null always means empty dictionary, but I'm not sure if that's applicable to a dictionary in a union as well. |
I may have hidden my point in some of the details.
6ac261b was the commit that happened to make the change that allowed My suggestion is that we return to the prohibition against explicitly nullable dictionaries everywhere, so |
It is. Note step 3 in https://heycam.github.io/webidl/#es-union, where if the JS value is |
That's only if the union type does not include a nullable type, due to step 1:
Looking at https://heycam.github.io/webidl/#es-dictionary I don't think nested dictionaries are a concern. So I think I agree that we can disallow explicitly nullable dictionaries. Is |
I wonder we should check whether any existing spec will be affected, since the resulting value would be different anyway (null vs. an empty dictionary). |
Ah yes, we should check return values. |
Also for non-return-value cases, because undefined foo(Bar? bar); here |
Already disallowed, check the paragraph a little below the list at https://heycam.github.io/webidl/#dfn-number-of-nullable-member-types:
Ahhhh, I'd skipped over that somehow, right. So while the set of input values accepted is identical, the IDL value that comes out of the conversion is different. I don't think there's a great reason to change that, particularly if there's any existing specs depending on it. Okay, so my real concern is just making the rules consistent rather than arbitrary (so I can write parallel consistent rules for That is, taking the cases mentioned earlier:
|
@saschanaz per
that is disallowed. I would be curious about the cases where we still allow T? with T being a dictionary and if they occur in practice. It seems like that would be return values and attributes? (It's also explicitly disallowed for nested dictionaries.) If we can completely disallow it I think that would be better. |
Ah right, but not everywhere though. |
As far as I can tell, while Looking over the rest of the sections...
So aside from callback functions (which are fairly rare and I doubt use nullable dicts anywhere), only the newest sorts of constructs can return a nullable dict, and it should be safe (not to mention consistent) to ban them there as well. That leaves us with just arguments that can still potentially take nullable dicts. @saschanaz any reasonable way to search for instances of this? |
The best way I can think of is to play with webidl2.js and webref with some added checks. |
YUP |
@tabatkins any interest in fixing this one too since we finally merged your undefined PR? We can promise quicker reviews this time :) |
Yeah I'm happy to, I'll try to get to it next week. |
https://heycam.github.io/webidl/#idl-operations
So I think it also wants to prevent dictionaries from being nullable there, although Edit: I tweaked webidl2.js, ran it on webref, and found no argument with nullable dictionaries including ones in unions. 🎉 |
Per https://heycam.github.io/webidl/#idl-nullable-type, dictionary types are allowed to be nullable (they're not excluded by any of the conditions), but unions containing dictionary types can't be nullable.
That is,
MyDict?
is valid, but(MyDict or DOMString)?
is not.This doesn't seem to make sense. Per https://heycam.github.io/webidl/#es-dictionary, JS
null
is always acceptable to convert to a dictionary type; nullability doesn't enter into the equation at all. In other words, dictionary types are implicitly nullable. You can also see this more easily in https://heycam.github.io/webidl/#es-union, where bothnull
andundefined
can be turned into a dictionary type if a union includes one.Tracing the blame back, this change occurred in 6ac261b, with the reasoning given being "Disallow dictionaries from being nullable only as operation argument types.". But that edit preserved the fact that JS
null
is always convertable to a dictionary type, so I'm not sure what it was actually trying to do.I suggest that we revert that change and just always disallow dictionary types from being nullable (since they're always implicitly nullable already).
The text was updated successfully, but these errors were encountered: