Skip to content
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

Consider disallowing optional dictionary arguments that have required members #793

Open
bzbarsky opened this issue Sep 5, 2019 · 5 comments

Comments

@bzbarsky
Copy link
Collaborator

bzbarsky commented Sep 5, 2019

Consider this IDL:

dictionary X {
  required boolean myVal;
};

interface Foo {
  void bar(optional X arg);
};

This is currently allowed by the spec. But in terms of behavior, what does the implementation of bar do if the dictionary is not passed? Specifically, what does it use in the place where it was going to use myVal? I can see a few options:

  1. It treats it effectively as a tristate, with no value if the dictionary was not passed. But then it could just make it optional in the dictionary too.

  2. It assumes a value for myVal (true or false). Then it could just make it optional in the dictionary and give it a default value.

Either way, it doesn't make sense to have this dictionary member be required in this situation. Hence I would propose that we disallow optional arguments whose type is a dictionary with required members. It might still make sense to have optional dictionary members whose type is a dictionary that has required members, I guess...

@domenic @annevk @saschanaz @Ms2ger thoughts?

@bzbarsky
Copy link
Collaborator Author

bzbarsky commented Sep 5, 2019

I should note that there are no cases like the one I am proposing disallowing in the parts of the web platform Gecko implements right now, and in fact Gecko's code generator fails out in that situation. That is not what prompted me to file this issue; @foolip's comments in w3c/webidl2.js#407 did, but it's a data point in terms of whether people would be affected in practice.

@Ms2ger
Copy link
Member

Ms2ger commented Sep 5, 2019

Hence I would propose that we disallow optional arguments whose type is a dictionary with required members.

Makes sense to me.

It might still make sense to have optional dictionary members whose type is a dictionary that has required members, I guess...

I think we might as well disallow it.

@bzbarsky
Copy link
Collaborator Author

bzbarsky commented Sep 5, 2019

I think we might as well disallow it.

See #76 (comment) -- people are using that pattern in specs...

@saschanaz
Copy link
Member

people are using that pattern in specs...

Only for dictionary members, right? I see no special value to allow it for arguments, where things like whatwg/html#5064 is just broken and not really optional.

BTW, do you recall which specs use that pattern?

@bzbarsky
Copy link
Collaborator Author

BTW, do you recall which specs use that pattern?

https://w3c.github.io/media-capabilities/#media-configurations is an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants