speced / bikeshed

:bike: A preprocessor for anyone writing specifications that converts source files into actual specs.
https://speced.github.io/bikeshed
Creative Commons Zero v1.0 Universal
1.11k stars 200 forks source link

Bikeshed seems to incorrectly use the last occurence of type for method argument validation #1566

Open bialpio opened 4 years ago

bialpio commented 4 years ago

When attempting to generate a spec from the below .bs file, bikeshed raises an error FATAL ERROR: IDL ERROR LINE: 5 - Dictionary argument "init" without required members must be marked optional. The error goes away either when the entire partial dictionary FakeXRDeviceInit gets uncommented, when making FakeXRDeviceInit init argument to simulateDeviceConnection method optional, or when adding some required key to the partial dictionary FakeXRDeviceInit. It seems that when validating method arguments, bikeshed only takes into account the latest occurrence of the FakeXRDeviceInit dictionary & checks if it has any required keys, instead of looking at all the keys present in the definition (including the ones introduced by partial definitions).

<pre class="metadata">
Status: DREAM
Shortname: bikeshed-sandbox
Title: Bikeshed Sandbox
Editor: you

Abstract: Used for experiments with bikeshed.
</pre>

<script type="idl">
interface FakeXRDevice {};

interface XRTest {
  Promise<FakeXRDevice> simulateDeviceConnection(FakeXRDeviceInit init);
};

dictionary FakeXRDeviceInit {
    required boolean supportsImmersive;
};

partial dictionary FakeXRDeviceInit {
};

</script>
tabatkins commented 4 years ago

Indeed, pretty certain that's exactly what I do; within a single spec you shouldn't be defining something both as a base and as a partial. ^_^

That said, I suspect the same problem would occur if a spec extended a dictionary defined elsewhere, and then used it.

bialpio commented 4 years ago

Thanks for confirming! I've unblocked myself by moving the keys that I wanted to introduce in a partial definition up to the main definition. This might be more difficult to work around in multi-spec scenario though.

cabanier commented 4 years ago

I'm also running in this issue. In a new spec, I'm defining a dictionary that has required members and then I have 3 dictionaries that inherit from it and that have no required members. Then, when I compile the spec I get:

FATAL ERROR: IDL ERROR LINE: 119 - Dictionary argument "init" without required members must be marked optional