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

Detect whether a dictionary member was set by default or not #1300

Open
beaufortfrancois opened this issue Apr 28, 2023 · 2 comments
Open

Detect whether a dictionary member was set by default or not #1300

beaufortfrancois opened this issue Apr 28, 2023 · 2 comments

Comments

@beaufortfrancois
Copy link

It would be nice if WebIDL would provide a way to know whether a dictionary member was set by default or not.

dictionary MyDictionary {
    required boolean myRequiredMember;
    boolean myOptionalMember = false;
};

In that case, myOptionalMember could be false because it was either set explicitly by developer with { myRequiredMember: true, myOptionalMember: false } or because it was not with { myRequiredMember: true }.

Having a way to detect this would allow implementations to warn developers that a dictionary was partially specified which may result in unexpected behaviour. For instance, { myRequiredMember: true, myOptionalMemberWithTypo: true } would set myOptionalMember to false.

Some would argue that if it's the case dictionary members should be declared required. I'm not sure about it. Providing default values is good but typos exist. I'd like to see efforts on that front.

@annevk
Copy link
Member

annevk commented Apr 28, 2023

How is myOptionalMemberWithTypo different to a potential future member the implementation might not yet understand?

In any event, if an implementation wanted to warn for this they already can. They'd just implement the defaulting outside of IDL.

@bathos
Copy link
Contributor

bathos commented Apr 30, 2023

It would be very surprising to me to receive a warning when making use of a feature that’s seemingly been deliberately designed to improve developer ergonomics. It also would seem arbitrary to single out default dictionary member values without also warning for default argument values; they are two realizations of the same concept.

aarongable pushed a commit to chromium/chromium that referenced this issue May 3, 2023
This CL adds a DevTools console warning when a GPUBlendComponent is
partially specified. Even though those have good default values, it
is still useful to warn developers about it.

I've filed WebIDL issue at whatwg/webidl#1300
to see if we can get WebIDL to change their behavior to not alter our
IDL files.

Bug: dawn:1785
Change-Id: I234419108cb92854d886e64f7b30c0fce173c5e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4481266
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Fr <beaufort.francois@gmail.com>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1139124}
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

4 participants
@beaufortfrancois @annevk @bathos and others