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

fix(productions/argument): no default for nullable dictionary args #395

Merged
merged 3 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/productions/argument.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@ export class Argument extends Base {
*validate(defs) {
yield* this.idlType.validate(defs);
if (idlTypeIncludesDictionary(this.idlType, defs)) {
if (this.optional && !this.default) {
if (this.idlType.nullable) {
const message = `Dictionary arguments cannot be nullable.`;
yield validationError(this.source, this.tokens.name, this, message);
} else if (this.optional && !this.default) {
const message = `Optional dictionary arguments must have a default value of \`{}\`.`;
yield validationError(this.source, this.tokens.name, this, message, {
autofix: autofixOptionalDictionaryDefaultValue(this)
});
}
if (this.idlType.nullable) {
const message = `Dictionary arguments cannot be nullable.`;
yield validationError(this.source, this.tokens.name, this, message);
}
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions test/invalid/baseline/argument-dict-nullable.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
Validation error at line 13 in argument-dict-nullable.webidl, inside `argument dict`:
x1(optional Dict? dict);
^ Dictionary arguments cannot be nullable.
Validation error at line 14 in argument-dict-nullable.webidl, inside `argument dict`:
x2(optional Dict? dict = {})
^ Dictionary arguments cannot be nullable.
Validation error at line 14 in argument-dict-nullable.webidl:
Validation error at line 15 in argument-dict-nullable.webidl:
(optional (boolean or Dict)? union =
^ Nullable union cannot include a dictionary type
Validation error at line 14 in argument-dict-nullable.webidl, inside `argument union`:
Validation error at line 15 in argument-dict-nullable.webidl, inside `argument union`:
boolean or Dict)? union = {})
^ Dictionary arguments cannot be nullable.
Validation error at line 15 in argument-dict-nullable.webidl:
Validation error at line 16 in argument-dict-nullable.webidl:
void z2(optional Union? union = {
^ Nullable union cannot include a dictionary type
Validation error at line 15 in argument-dict-nullable.webidl, inside `argument union`:
Validation error at line 16 in argument-dict-nullable.webidl, inside `argument union`:
z2(optional Union? union = {})
^ Dictionary arguments cannot be nullable.
Validation error at line 16 in argument-dict-nullable.webidl, inside `argument req`:
Validation error at line 17 in argument-dict-nullable.webidl, inside `argument req`:
void r(Required? req);
^ Dictionary arguments cannot be nullable.
1 change: 1 addition & 0 deletions test/invalid/idl/argument-dict-nullable.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ typedef (short or Dict) Union;

[Exposed=Window]
interface X {
void x1(optional Dict? dict);
void x2(optional Dict? dict = {});
void y2(optional (boolean or Dict)? union = {});
void z2(optional Union? union = {});
Expand Down