Re: new overloading model

On Tue, 20 Dec 2011 23:26:19 +0100, Cameron McCormack <cam@mcc.id.au>  
wrote:

> Cameron McCormack:
>>> Ignoring the issue of explicitly passing undefined meaning "consider
>>> this an un-passed optional argument" and whether we want to revisit
>>> that (http://www.w3.org/mid/4EEEA0F0.5010906@mcc.id.au), overload
>>> resolution in this proposal goes as follows:
>>>
>>> * Generate the "effective overload set" for the given identifier
>>> and argument list length. Union types do not get expanded out
>>> into multiple entries like optional arguments do.
>>>
>>> * For each argument position:
>>>
>>> * For each entry in the effective overload set:
>>>
>>> * If the type is one of the exactly matching types mentioned
>>> above, or is a union type consisting only of the exactly
>>> matching types, and the JS value passed in does not match
>>> it, then disqualify this entry.
>
> Simon Pieters:
>> For nullable types, null is considered to match?
>
> Yes.
>
>> What about
>>
>> void f(DOMString? x);
>> void f(Node? x);
>>
>> Both would qualify if null is passed in (actually even if the DOMString
>> type isn't nullable).
>
> That's not allowed, since "DOMString?" and "Node?" are not  
> distinguishable.

OK, but doesn't this give two candidates?

     void add(HTMLOptionElement element, optional HTMLElement? before);
     void add(HTMLOptGroupElement element, optional HTMLElement? before);
     void add(HTMLOptionElement element, long before);
     void add(HTMLOptGroupElement element, long before);

options.add(document.createElement('option'), null);

(Same with "DOMString" and "Node?".)


>> Similarly, what about nullable unions?
>>
>> void f(DOMString? or Node? x);
>
> Again that would not be allowed, since the members of the union all have  
> to be distinguishable (apart from primitives and DOMString).  You could  
> write "(DOMString or Node)?" or "DOMString or Node?".
>
> ...
>> Overall looks good to me!
>
> Great!


-- 
Simon Pieters
Opera Software

Received on Wednesday, 21 December 2011 07:44:04 UTC