Skip to content

Commit ee37748

Browse files
committed
Specify the error that arises when we cause a private override "from the outside" by a mixin application
1 parent 69c5622 commit ee37748

File tree

1 file changed

+78
-27
lines changed

1 file changed

+78
-27
lines changed

specification/dartLangSpec.tex

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5465,42 +5465,93 @@ \subsection{Mixin Application}
54655465
A mixin may be applied to a superclass, yielding a new class.
54665466

54675467
\LMHash{}%
5468-
Let $S$ be a class,
5469-
$M$ be a mixin with \NoIndex{required superinterface}s $T_1$, \ldots, $T_n$,
5470-
\NoIndex{combined superinterface} $M_S$,
5471-
\NoIndex{implemented interfaces} $I_1$, \ldots, $I_k$ and
5472-
\metavar{members} as \NoIndex{mixin member declarations},
5473-
and let $N$ be a name.
5468+
\BlindDefineSymbol{S, S'}%
5469+
Let $S$ be a class, and let $S'$ be a parameterized type of the form
5470+
\code{$S$<$\cdots$>}.
5471+
\commentary{%
5472+
This includes the case where $S$ is non-generic and $S'$ is $S$.%
5473+
}
5474+
5475+
\LMHash{}%
5476+
\BlindDefineSymbol{M, \metavar{members}}%
5477+
Let $M$ be a mixin with member declarations \metavar{members}.
5478+
\BlindDefineSymbol{M', T_j}%
5479+
Let $M'$ be a parameterized type of the form
5480+
\code{$M$<$\cdots$>}
5481+
\commentary{(again including the case where $M'$ is $M$)}.
5482+
Let \List{T}{1}{n} be the required superinterfaces,
5483+
\BlindDefineSymbol{M_S, I_j}
5484+
$M_S$ the combined superinterface,
5485+
\List{I}{1}{k} the implemented interfaces,
5486+
all of $M$ and corresponding to $M'$.
54745487

54755488
\LMHash{}%
5476-
It is a compile-time error to apply $M$ to $S$ if $S$ does not implement,
5477-
directly or indirectly, all of $T_1$, \ldots, $T_n$.
5489+
It is a compile-time error to apply $M'$ to $S'$
5490+
unless $S'$ implements each of \List{T}{1}{n}
5491+
(\ref{interfaceSuperinterfaces}).
54785492
It is a compile-time error if any of \metavar{members} contains a
5479-
super-invocation of a member $m$ \commentary{(for example \code{super.foo},
5480-
\code{super + 2}, or \code{super[1] = 2})}, and $S$ does not have a concrete
5481-
implementation of $m$ which is a valid override of the member $m$ in
5482-
the interface $M_S$. \rationale{We treat super-invocations in mixins as
5483-
interface invocations on the combined superinterface, so we require the
5484-
superclass of a mixin application to have valid implementations of those
5485-
interface members that are actually super-invoked.}
5486-
5487-
\LMHash{}%
5488-
The mixin application of $M$ to $S$ with name $N$ introduces a new
5489-
class, $C$, with name $N$, superclass $S$,
5490-
implemented interface $M$
5491-
and \metavar{members} as instance members.
5493+
super-invocation of a member $m$
5494+
\commentary{%
5495+
(for example \code{super.foo}, \code{super + 2}, or \code{super[1] = 2})%
5496+
},
5497+
and $S'$ does not have a concrete implementation of $m$ which is
5498+
a valid override of the member $m$ in the interface $M_S$.
5499+
\rationale{%
5500+
We treat super-invocations in mixins as interface invocations on
5501+
the combined superinterface,
5502+
so we require the superclass of a mixin application to have
5503+
valid implementations of those interface members
5504+
that are actually super-invoked.%
5505+
}
5506+
5507+
\LMHash{}%
5508+
Let \DefineSymbol{L_C} be the library containing the mixin application.
5509+
\commentary{%
5510+
That is, the library containing the clause \code{$S$ \WITH{} $M$}
5511+
or the clause \code{$S_0$ \WITH{} $M_1$, \ldots,\ $M_k$, $M$} giving rise
5512+
to the mixin application.%
5513+
}
5514+
Let \DefineSymbol{L_M} be the library containing the declaration of $M$.
5515+
5516+
\LMHash{}%
5517+
Assume that $S$ has a member $m_S$ which is accessible to $L_M$,
5518+
that $m_S$ has the name $n$ which is private
5519+
(\commentary{so $m_S$ is declared in $L_M$}),
5520+
and that $M$ declares a member $m_M$ which is also named $n$
5521+
\commentary{(note that $m_M$ is also declared in $L_M$)}.
5522+
In this case a compile-time error occurs.
5523+
5524+
\commentary{%
5525+
In this situation $m_M$ would override $m_S$ if $M'$ is applied to $S'$,
5526+
and this happens because of the mixin application which is outside of $L_M$,
5527+
even though $m_M$ and $m_S$ are private.
5528+
One of the unfortunate consequences of this situanion is that
5529+
invocations of $m_S$ which could otherwise be statically resolved
5530+
(in cases where it is otherwise guaranteed that $m_S$ is not overridden)
5531+
must now be invoked using late binding.
5532+
Because of this, and because of some other complications,
5533+
this kind of ``private overriding from outside'' is prevented by making it
5534+
a compile-time error to perform the mixin application.%
5535+
}
5536+
5537+
\LMHash{}%
5538+
Let \DefineSymbol{N} be a name.
5539+
The
5540+
\Index{mixin application}
5541+
of $M'$ to $S'$ with name $N$
5542+
introduces a new class, \DefineSymbol{C},
5543+
with name $N$, superclass $S'$, implemented interface $M'$,
5544+
and instance members
5545+
which are the concrete declarations in \metavar{members},
5546+
substituting type variables of $M$ corresponding to $M'$.
54925547
The class $C$ has no static members.
54935548
If $S$ declares any generative constructors, then the application
54945549
introduces generative constructors on $C$ as follows:
54955550

54965551
\LMHash{}%
5497-
Let $L_C$ be the library containing the mixin application.
5498-
\commentary{That is, the library containing the clause \code{$S$ \WITH{} $M$}
5499-
or the clause \code{$S_0$ \WITH{} $M_1$, \ldots,\ $M_k$, $M$} giving rise
5500-
to the mixin application.}
5501-
5502-
Let $S_N$ be the name of $S$.
5552+
Let \DefineSymbol{S_N} be the name of $S$.
55035553

5554+
\LMHash{}%
55045555
For each generative constructor of the form
55055556
\code{$S_q$($T_{1}$ $a_{1}$, $\ldots$, $T_{k}$ $a_{k}$)}
55065557
of $S$ that is accessible to $L_C$, $C$ has

0 commit comments

Comments
 (0)