-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Promise<T> uses return-type in an inconsistent way; union types don't use type at all #537
Comments
Thank you for raising this! This could be fixed, but I wonder we could remove the whole Pinging @sidvishnoi to confirm this. |
Well, it's still useful to distinguish But I think |
Ah yes, I mean only |
@saschanaz Confirming ReSpec is not using |
Usually the rule seems to be that the top-most parent of a Type sets the
type
field all the way down.attribute-type
, for example, gets propagated down into sequence types, etc.However,
union
types have thetype
property set tonull
, and these fields are not recursed into when setting theattribute-type
value or whathaveyou.Also
Promise<T>
sets thetype
property of theT
type toreturn-type
, and again that is robust and doesn't get overwritten withattribute-type
--- but only when T isvoid
.In my PHP port, this leads to the somewhat baroque logic in the
setType
method here:https://github.com/cscott/WebIDL/blob/main/src/Grammar.pegphp#L54
which has to take care not to overwrite this single type in the
Promise<void>
child set here:https://github.com/cscott/WebIDL/blob/main/src/Grammar.pegphp#L764
In this repo's test cases, you can see the unusual behavior here, for
Promise<void>
(which getsreturn-type
notattribute-type
):https://github.com/w3c/webidl2.js/blob/gh-pages/test/syntax/baseline/promise-void.json#L18
and here (
Promise<DOMString>
getsattribute-type
notreturn-type
):https://github.com/w3c/webidl2.js/blob/gh-pages/test/syntax/baseline/generic.json#L60
And here is where you can see a union getting
null
as it'stype
instead of inheritingattribute-type
:https://github.com/w3c/webidl2.js/blob/gh-pages/test/syntax/baseline/uniontype.json#L18
This isn't necessarily a bug per se -- my PHP port can emulate this behavior consistently, and it's only two or three lines of code -- but it does seem... "non-orthogonal"... so I thought I'd mention it in case you want to clean it up.
I'd suggest consistently recursing into type children including union types, and getting rid of the
return-type
marker onPromise<void>
and letting that be recursed into like all other types.The text was updated successfully, but these errors were encountered: