Skip to content

Commit

Permalink
[LC-70] Disallow overloads across partial interface definitions. Disa…
Browse files Browse the repository at this point in the history
…llow overloading where two interface types are distinguished but one is an ancestor of the other. Define exactly how disambiguation occurs when interface types are involved.
  • Loading branch information
heycam committed Nov 6, 2013
1 parent 510ac3d commit bae069c
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 68 deletions.
127 changes: 88 additions & 39 deletions Overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Web IDL</title>
<meta name="revision" content="$Id: Overview.html,v 1.403 2011-10-24 17:34:29 cmccorma Exp $" />
<meta name="revision" content="$Id: Overview.html,v 1.404 2011-10-24 21:06:07 cmccorma Exp $" />
<link rel="stylesheet" href="WebIDL.css" type="text/css" />
<script src="section-links.js" type="application/ecmascript"></script>
<script src="dfn.js" type="application/ecmascript"></script>
Expand Down Expand Up @@ -906,7 +906,8 @@ <h3>3.3. Interfaces</h3>
<i>interface-members…</i>
};</pre>
<p>
The order that members appear in has no significance.
The order that members appear in has no significance except in the
case of <a href="#idl-overloading">overloading</a>.
</p>
<p>
Interfaces may specify an interface member that has the same name as
Expand Down Expand Up @@ -1033,11 +1034,15 @@ <h3>3.3. Interfaces</h3>
<i>interface-members…</i>
};</pre>
<p>
The order of apperance of an <a class="dfnref" href="#dfn-interface">interface</a>
The order of appearance of an <a class="dfnref" href="#dfn-interface">interface</a>
definition and any of its <a class="dfnref" href="#dfn-partial-interface">partial interface</a>
definitions within a single <a class="dfnref" href="#dfn-idl-fragment">IDL fragment</a>
does not matter.
</p>
<p>
<a class="dfnref" href="#dfn-extended-attribute">Extended attributes</a> <span class="rfc2119">MUST NOT</span>
be specified on <a class="dfnref" href="#dfn-partial-interface">partial interface</a> definitions.
</p>
<div class="note"><div class="noteHeader">Note</div>
<p>Partial interface definitions are intended for use as a specification
editorial aide, allowing the definition of an interface to be separated
Expand Down Expand Up @@ -2400,6 +2405,32 @@ <h4>3.3.6. Overloading</h4>
specified to take, and in order to describe these restrictions,
the notion of an <em>effective overload set</em> is used.
</p>
<p>
<a class="dfnref" href="#dfn-operation">Operations</a> and <a class="dfnref" href="#dfn-legacy-caller">legacy callers</a>
<span class="rfc2119">MUST NOT</span> be overloaded across <a class="dfnref" href="#dfn-interface">interface</a>
and <a class="dfnref" href="#dfn-partial-interface">partial interface</a> definitions.
</p>
<div class="note"><div class="noteHeader">Note</div>
<p>
For example, the overloads for both <span class="idltype">f</span> and <span class="idltype">g</span>
are disallowed:
</p>
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface A {
void f();
};

partial interface A {
void f(float x);
void g();
};

partial interface A {
void g(DOMString x);
};</code></pre></div></div>
<p>Note that <a class="dfnref" href="#dfn-extended-attribute">extended attributes</a> are disallowed from appearing
on <a class="dfnref" href="#dfn-partial-interface">partial interface</a> definitions,
so there is no need to also disallow overloading for constructors.</p>
</div>
<p>
An <dfn id="dfn-effective-overload-set">effective overload set</dfn>
for a given
Expand Down Expand Up @@ -2875,36 +2906,37 @@ <h4>3.3.6. Overloading</h4>
</tr>
</table>
<ul class="notes">
<li id="distinguishable-interface-note"><a class="note-link">[1]</a> Two <a href="#idl-interface">interface types</a> are distinguishable only if two different <a class="dfnref" href="#dfn-interface">interfaces</a> are identified.</li>
<li id="distinguishable-interface-note"><a class="note-link">[1]</a> Two <a href="#idl-interface">interface types</a> are distinguishable only if two different <a class="dfnref" href="#dfn-interface">interfaces</a> are identified and if one is not an <a class="dfnref" href="#dfn-inherited-interfaces">inherited interface</a> of the other.</li>
</ul>
<div class="note"><div class="noteHeader">Note</div>
<!--
<div class='note'>
<p>
These restrictions on argument types reduce
the possibility of resolution ambiguity in
<a class="dfnref" href="#dfn-overloaded">overloaded</a> operations
<a class='dfnref' href='#dfn-overloaded'>overloaded</a> operations
and constructors, but do not completely
eliminate it. In the ECMAScript language binding, the
restrictions still can result in overloaded operation and constructor invocations
that cannot be distinguished solely based on the values passed to
the corresponding function. For example, with the following
<a class="dfnref" href="#dfn-interface">interfaces</a>:
<a class='dfnref' href='#dfn-interface'>interfaces</a>:
</p>
<div class="block"><div class="blockTitleDiv"><span class="blockTitle">IDL</span></div><div class="blockContent"><pre class="code"><code class="idl-code">interface A {
<span class="comment">// ...</span>
<x:codeblock language='idl'>interface A {
<span class='comment'>// ...</span>
};

interface B {
<span class="comment">// ...</span>
<span class='comment'>// ...</span>
};

interface C {
void f(A? x);
void f(B? x);
};</code></pre></div></div>
};</x:codeblock>
<p>
it is possible to pass an object that implements both <span class="idltype">A</span>
and <span class="idltype">B</span> to <code>f</code>. Similarly,
passing <span class="esvalue">null</span> to <code>f</code>
it is possible to pass an object that implements both <span class='idltype'>A</span>
and <span class='idltype'>B</span> to <code>f</code>. Similarly,
passing <span class='esvalue'>null</span> to <code>f</code>
would also be ambiguous. Since the ECMAScript
language binding provides no way to disambiguate such calls,
the interface description will need to
Expand All @@ -2915,6 +2947,7 @@ <h4>3.3.6. Overloading</h4>
actually implement the two interfaces, for example.)
</p>
</div>
-->
<div class="example"><div class="exampleHeader">Example</div>
<p>
For the following interface:
Expand Down Expand Up @@ -8277,14 +8310,10 @@ <h5>4.5.1.1. Interface object [[Call]] method</h5>
If <var>S</var> is empty, throw a <span class="estype">TypeError</span>.
</li>
<li>
If <var>S</var> contains more than one entry, then the
constructor call is ambiguous. Remove all but one entry from
<var>S</var> according to rules specified in the description
of <a class="dfnref" href="#dfn-interface">interface</a>
<var>I</var>. If these rules do not sufficiently disambiguate the
call, then the behavior of the function call (including whether
it selects a particular overload or simply throws an exception)
is undefined.
If <var>S</var> contains more than one entry, then remove from
<var>S</var> all entries except the one whose corresponding constructor
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
appears earliest on the interface.
</li>
<li>
Let <var>x</var> be the <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
Expand Down Expand Up @@ -8413,11 +8442,10 @@ <h4>4.5.2. Named constructors</h4>
If <var>S</var> is empty, throw a <span class="estype">TypeError</span>.
</li>
<li>
If <var>S</var> contains more than one entry, then the
constructor call is ambiguous. Remove all but one entry from
<var>S</var> according to rules specified in the description
of <a class="dfnref" href="#dfn-interface">interface</a>
<var>I</var>, or arbitrarily if no such rules exist.
If <var>S</var> contains more than one entry, then remove from
<var>S</var> all entries except the one whose corresponding constructor
<a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
appears earliest on the interface.
</li>
<li>
Let <var>x</var> be the <a class="dfnref" href="#dfn-extended-attribute">extended attribute</a>
Expand Down Expand Up @@ -8837,11 +8865,9 @@ <h4>4.5.6. Operations</h4>
If <var>S</var> is empty, throw a <span class="estype">TypeError</span>.
</li>
<li>
If <var>S</var> contains more than one entry, then the
operation call is ambiguous. Remove all but one entry from
<var>S</var> according to rules specified in the description
of <a class="dfnref" href="#dfn-interface">interface</a>
<var>I</var>, or arbitrarily if no such rules exist.
If <var>S</var> contains more than one entry, then remove from
<var>S</var> all entries except the one whose corresponding operation
definition appears earliest on the interface.
</li>
<li>
Let <var>op</var> be the operation and <var>t</var><sub>0..<var>m</var>−1</sub>
Expand Down Expand Up @@ -9502,10 +9528,9 @@ <h4>4.7.5. Platform object [[Call]] method</h4>
<var>arg</var><sub>0..<var>n</var>−1</sub> to the
<a class="dfnref" href="#dfn-overload-resolution-algorithm">overload resolution algorithm</a>.</li>
<li>If <var>S</var> is empty, throw a <span class="estype">TypeError</span>.</li>
<li>If <var>S</var> contains more than one entry, then the call is ambiguous. Remove all but
one entry from <var>S</var> according to the rules specified in the description of
<a class="dfnref" href="#dfn-interface">interface</a> <var>I</var>, or arbitrarily
if no such rules exist.</li>
<li>If <var>S</var> contains more than one entry, then remove from <var>S</var>
all entries except the one whose corresponding legacy caller appears
earliest on the interface.</li>
<li>Let <var>op</var> be the operation and <var>t</var><sub>0..<var>m</var>−1</sub> be the type list
of the single entry in <var>S</var>.</li>
<li>Let <var>idlarg</var><sub>0..<var>m</var>−1</sub> be a list of IDL values,
Expand Down Expand Up @@ -12143,6 +12168,7 @@ <h2>9. Acknowledgements</h2>
Dominique Hazaël-Massieux,
Ian Hickson,
Björn Höhrmann,
Kyle Huey,
Dimitry Golubovsky,
Kartikaya Gupta,
James Graham,
Expand Down Expand Up @@ -12504,10 +12530,33 @@ <h2>C. Changes</h2>
The following is a list of substantial changes to the document on each publication.
</p>
<dl class="changes">
<dt>27 September 2011 – LCWD #2</dt>
<!--
<dt>Current editor’s draft</dt>
-->
<dd>
<ul>
<li>
<p>
Disallowed overloading that distinguishes between two interface types
where one is an inherited interface of the other.
</p>
</li>
<li>
<p>
Disallowed overloading across separate interface and partial interface
definitions.
</p>
</li>
<li>
<p>
Removed the ability for specifications to disambiguate overloaded
operation calls for cases that are still technically distinguishable,
such as distinguishing based on interface type. Also defined that
otherwise ambiguous calls involving interface types are resolved
by selecting the overload that appears earliest on the interface.
</p>
</li>
</ul>
</dd>
<dt>27 September 2011 – LCWD #2</dt>
<dd>
<ul>
<li>
Expand Down
Loading

0 comments on commit bae069c

Please sign in to comment.