@@ -5452,42 +5452,93 @@ \subsection{Mixin Application}
5452
5452
A mixin may be applied to a superclass, yielding a new class.
5453
5453
5454
5454
\LMHash{}%
5455
- Let $S$ be a class,
5456
- $M$ be a mixin with \NoIndex{required superinterface}s $T_1$, \ldots, $T_n$,
5457
- \NoIndex{combined superinterface} $M_S$,
5458
- \NoIndex{implemented interfaces} $I_1$, \ldots, $I_k$ and
5459
- \metavar{members} as \NoIndex{mixin member declarations},
5460
- and let $N$ be a name.
5455
+ \BlindDefineSymbol{S, S'}%
5456
+ Let $S$ be a class, and let $S'$ be a parameterized type of the form
5457
+ \code{$S$<$\cdots$>}.
5458
+ \commentary{%
5459
+ This includes the case where $S$ is non-generic and $S'$ is $S$.%
5460
+ }
5461
+
5462
+ \LMHash{}%
5463
+ \BlindDefineSymbol{M, \metavar{members}}%
5464
+ Let $M$ be a mixin with member declarations \metavar{members}.
5465
+ \BlindDefineSymbol{M', T_j}%
5466
+ Let $M'$ be a parameterized type of the form
5467
+ \code{$M$<$\cdots$>}
5468
+ \commentary{(again including the case where $M'$ is $M$)}.
5469
+ Let \List{T}{1}{n} be the required superinterfaces,
5470
+ \BlindDefineSymbol{M_S, I_j}
5471
+ $M_S$ the combined superinterface,
5472
+ \List{I}{1}{k} the implemented interfaces,
5473
+ all of $M$ and corresponding to $M'$.
5461
5474
5462
5475
\LMHash{}%
5463
- It is a compile-time error to apply $M$ to $S$ if $S$ does not implement,
5464
- directly or indirectly, all of $T_1$, \ldots, $T_n$.
5476
+ It is a compile-time error to apply $M'$ to $S'$
5477
+ unless $S'$ implements each of \List{T}{1}{n}
5478
+ (\ref{interfaceSuperinterfaces}).
5465
5479
It is a compile-time error if any of \metavar{members} contains a
5466
- super-invocation of a member $m$ \commentary{(for example \code{super.foo},
5467
- \code{super + 2}, or \code{super[1] = 2})}, and $S$ does not have a concrete
5468
- implementation of $m$ which is a valid override of the member $m$ in
5469
- the interface $M_S$. \rationale{We treat super-invocations in mixins as
5470
- interface invocations on the combined superinterface, so we require the
5471
- superclass of a mixin application to have valid implementations of those
5472
- interface members that are actually super-invoked.}
5473
-
5474
- \LMHash{}%
5475
- The mixin application of $M$ to $S$ with name $N$ introduces a new
5476
- class, $C$, with name $N$, superclass $S$,
5477
- implemented interface $M$
5478
- and \metavar{members} as instance members.
5480
+ super-invocation of a member $m$
5481
+ \commentary{%
5482
+ (for example \code{super.foo}, \code{super + 2}, or \code{super[1] = 2})%
5483
+ },
5484
+ and $S'$ does not have a concrete implementation of $m$ which is
5485
+ a valid override of the member $m$ in the interface $M_S$.
5486
+ \rationale{%
5487
+ We treat super-invocations in mixins as interface invocations on
5488
+ the combined superinterface,
5489
+ so we require the superclass of a mixin application to have
5490
+ valid implementations of those interface members
5491
+ that are actually super-invoked.%
5492
+ }
5493
+
5494
+ \LMHash{}%
5495
+ Let \DefineSymbol{L_C} be the library containing the mixin application.
5496
+ \commentary{%
5497
+ That is, the library containing the clause \code{$S$ \WITH{} $M$}
5498
+ or the clause \code{$S_0$ \WITH{} $M_1$, \ldots,\ $M_k$, $M$} giving rise
5499
+ to the mixin application.%
5500
+ }
5501
+ Let \DefineSymbol{L_M} be the library containing the declaration of $M$.
5502
+
5503
+ \LMHash{}%
5504
+ Assume that $S$ has a member $m_S$ which is accessible to $L_M$,
5505
+ that $m_S$ has the name $n$ which is private
5506
+ (\commentary{so $m_S$ is declared in $L_M$}),
5507
+ and that $M$ declares a member $m_M$ which is also named $n$
5508
+ \commentary{(note that $m_M$ is also declared in $L_M$)}.
5509
+ In this case a compile-time error occurs.
5510
+
5511
+ \commentary{%
5512
+ In this situation $m_M$ would override $m_S$ if $M'$ is applied to $S'$,
5513
+ and this happens because of the mixin application which is outside of $L_M$,
5514
+ even though $m_M$ and $m_S$ are private.
5515
+ One of the unfortunate consequences of this situanion is that
5516
+ invocations of $m_S$ which could otherwise be statically resolved
5517
+ (in cases where it is otherwise guaranteed that $m_S$ is not overridden)
5518
+ must now be invoked using late binding.
5519
+ Because of this, and because of some other complications,
5520
+ this kind of ``private overriding from outside'' is prevented by making it
5521
+ a compile-time error to perform the mixin application.%
5522
+ }
5523
+
5524
+ \LMHash{}%
5525
+ Let \DefineSymbol{N} be a name.
5526
+ The
5527
+ \Index{mixin application}
5528
+ of $M'$ to $S'$ with name $N$
5529
+ introduces a new class, \DefineSymbol{C},
5530
+ with name $N$, superclass $S'$, implemented interface $M'$,
5531
+ and instance members
5532
+ which are the concrete declarations in \metavar{members},
5533
+ substituting type variables of $M$ corresponding to $M'$.
5479
5534
The class $C$ has no static members.
5480
5535
If $S$ declares any generative constructors, then the application
5481
5536
introduces generative constructors on $C$ as follows:
5482
5537
5483
5538
\LMHash{}%
5484
- Let $L_C$ be the library containing the mixin application.
5485
- \commentary{That is, the library containing the clause \code{$S$ \WITH{} $M$}
5486
- or the clause \code{$S_0$ \WITH{} $M_1$, \ldots,\ $M_k$, $M$} giving rise
5487
- to the mixin application.}
5488
-
5489
- Let $S_N$ be the name of $S$.
5539
+ Let \DefineSymbol{S_N} be the name of $S$.
5490
5540
5541
+ \LMHash{}%
5491
5542
For each generative constructor of the form
5492
5543
\code{$S_q$($T_{1}$ $a_{1}$, $\ldots$, $T_{k}$ $a_{k}$)}
5493
5544
of $S$ that is accessible to $L_C$, $C$ has
0 commit comments