W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2012

Re: [webidl] Unions involving a primitive and a string don't make any sense

From: Cameron McCormack <cam@mcc.id.au>
Date: Sat, 31 Mar 2012 11:13:20 +1100
Message-ID: <4F764C20.3000201@mcc.id.au>
To: Boris Zbarsky <bzbarsky@MIT.EDU>
CC: public-script-coord@w3.org
Boris Zbarsky:
> In particular, unions are allowed to contain both a string (or enum) and
> a primitive, but if you try to convert a JS value to such a union the
> string is always picked (http://dev.w3.org/2006/webapi/WebIDL/#es-union
> step 7).  That seems wrong.

Yes, that's wrong.  The intention was to allow

   void f((float or DOMString) x);

to be written because

   void f(float x);
   void f(DOMString x);

was not allowed, since the two types are not distinguishable.  DOMString 
would be used as the type of last resort, but if a JS Number were passed 
then it would be converted into the float.

I wonder now with the changes we've made to simplify overloading if it's 
actually useful to have different behaviour between unions and overloads 
like this.  Probably not.  So we should either make primitives and 
DOMString distinguishable for overloading, defaulting to selecting 
DOMString when there isn't an exact type match like unions were meant to 
do, or unions shouldn't allow both types.

I'm not aware of an API that needs to handle floats and DOMStrings 
separately -- is there one?  If not, we should just disallow it.
Received on Saturday, 31 March 2012 00:13:56 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:06 UTC