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

On 3/30/12 8:13 PM, Cameron McCormack wrote:
> 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 don't see why the same thing can't be done in overload resolution, if 
it's really desired.

> 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.

That's my feeling too.

> 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.

This I don't know offhand.

-Boris

Received on Monday, 2 April 2012 06:42:14 UTC