Skip to content

Commit 63c6851

Browse files
lrhncommit-bot@chromium.org
authored andcommitted
Update induced mixin application constructor definition.
Change-Id: Ic6eeffd2e3d348f636af5ab4644cc60b87e85506 Reviewed-on: https://dart-review.googlesource.com/29060 Commit-Queue: Lasse R.H. Nielsen <[email protected]> Reviewed-by: Erik Ernst <[email protected]>
1 parent 8a6bdaa commit 63c6851

File tree

1 file changed

+64
-23
lines changed

1 file changed

+64
-23
lines changed

docs/language/dartLangSpec.tex

Lines changed: 64 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
% abstractly, to eliminate certain diagnostic messages.
4141
% - Add generic functions and methods to the language.
4242
% - Don't cause warning if a non-system library import shadows a system library.
43+
% - Update mixin application forwarding constructors to correctly handle
44+
% optional parameters and const constructors.
4345
%
4446
% 1.15
4547
% - Change how language specification describes control flow.
@@ -2215,7 +2217,7 @@ \subsection{Superclasses}
22152217
\LMLabel{superclasses}
22162218

22172219
\LMHash{}
2218-
The superclass of a class $C$ that has a with clause \code{\WITH{} $M_1, \ldots,\ M_k$} and an extends clause \code{\EXTENDS{} S} is the application of mixin (\ref{mixins}) $M_k* \cdots * M_1$ to S.
2220+
The superclass $S^\prime$ of a class $C$ that has a with clause \code{\WITH{} $M_1, \ldots,\ M_k$} and an extends clause \code{\EXTENDS{} $S$} is the application of mixin composition (\ref{mixins}) $M_k* \cdots * M_1$ to $S$. The name $S^\prime$ is a fresh identifier.
22192221
If no \WITH{} clause is specified then the \EXTENDS{} clause of a class $C$ specifies its superclass.
22202222
If no \EXTENDS{} clause is specified, then either:
22212223
\begin{itemize}
@@ -2554,7 +2556,8 @@ \section{Mixins}
25542556
A mixin is always derived from an existing class declaration.
25552557

25562558
\LMHash{}
2557-
It is a compile-time error if a declared or derived mixin explicitly declares a constructor which is not a factory constructor.
2559+
It is a compile-time error to derive a mixin from a class which explicitly declares a generative constructor.
2560+
It is a compile-time error to derive a mixin from a class which has a superclass other than \code{Object}.
25582561

25592562
\rationale{
25602563
This restriction is temporary.
@@ -2569,8 +2572,8 @@ \subsection{Mixin Application}
25692572

25702573
\LMHash{}
25712574
A mixin may be applied to a superclass, yielding a new class.
2572-
Mixin application occurs when a mixin is mixed into a class declaration via its \WITH{} clause.
2573-
The mixin application may be used to extend a class per section (\ref{classes}); alternately, a class may be defined as a mixin application as described in this section.
2575+
Mixin application occurs when one or more mixins are mixed into a class declaration via its \WITH{} clause.
2576+
The mixin application may be used to extend a class per section (\ref{classes}); alternatively, a class may be defined as a mixin application as described in this section.
25742577
It is a compile-time error if the \WITH{} clause of a mixin application $C$ includes a type variable (\ref{generics}), a type alias (\ref{typedef}), an enumerated type (\ref{enums}), a malformed type, or a deferred type (\ref{staticTypes}).
25752578

25762579
\begin{grammar}
@@ -2582,29 +2585,67 @@ \subsection{Mixin Application}
25822585
\end{grammar}
25832586

25842587
\LMHash{}
2585-
A mixin application of the form \code{$S$ \WITH{} $M$;} defines a class $C$ with superclass $S$.
2588+
A mixin application of the form \code{$S$ \WITH{} $M$;} for the name $N$ defines a class $C$ with superclass $S$ and name $N$.
25862589

25872590
\LMHash{}
2588-
A mixin application of the form \code{$S$ \WITH{} $M_1, \ldots,\ M_k$;} defines a class $C$ whose superclass is the application of the mixin composition (\ref{mixinComposition}) $M_{k-1} * \ldots * M_1$ to $S$.
2591+
A mixin application of the form \code{$S$ \WITH{} $M_1,\ \ldots, M_k$;} for the name $N$ defines a class $C$ whose superclass is the application of the mixin composition (\ref{mixinComposition}) $M_{k-1} * \ldots * M_1$ to $S$ of a name that is a fresh identifer, and whose name is $N$.
2592+
\rationale{The name of the resulting class is necessary because it is part of the names of the introduced constructors.}
25892593

25902594
\LMHash{}
25912595
In both cases above, $C$ declares the same instance members as $M$ (respectively, $M_k$).
2592-
If any of the instance variables of $M$ (respectively, $M_k$) have initializers, they are executed in the scope of $M$ (respectively, $M_k$) to initialize the corresponding instance variables of $C$.
2596+
If any of the instance variables of $M$ (respectively, $M_k$) have initializers,
2597+
they are executed in the instance scope of $M$ (respectively, $M_k$)
2598+
to initialize the corresponding instance variables of $C$.
25932599

25942600
\LMHash{}
2595-
Let $L_M$ be the library in which $M$ is declared.
2596-
For each generative constructor named
2597-
$q_i(T_{i1}\ a_{i1}, \ldots,\ T_{ik_i}\ a_{ik_i}), i \in 1 .. n$
2598-
of $S$ that is accessible to $L_M$,
2599-
$C$ has an implicitly declared constructor named
2600-
$q'_i = [C/S]q_i$ of the form
2601+
Let $L_C$ be the library containing the mixin application.
2602+
\commentary{That is, the library containing the clause \code{$S$ \WITH{} $M$}
2603+
or the clause \code{$S_0$ \WITH{} $M_1$, \ldots,\ $M_k$, $M$}.}
26012604

2602-
\code{$q'_i$($a_{i1}, \ldots,\ a_{ik_i}$): \SUPER($a_{i1}, \ldots,\ a_{ik_i}$);}.
2605+
Let $N_C$ be the name of the mixin application class $C$,
2606+
let $S$ be the superclass of $C$, and let $S_N$ be the name of $S$.
26032607

2604-
%super.id
2608+
For each generative constructor of the form \code{$S_q$($T_{1}$ $a_{1}$, $\ldots$, $T_{k}$ $a_{k}$)} of $S$ that is accessible to $L_C$, $C$ has an implicitly declared constructor of the form
2609+
\begin{dartCode}
2610+
$C_q$($T_{1}$ $a_{1}$, \ldots, $T_{k}$ $a_{k}$):$\SUPER_q$($a_{1}$, $\ldots$, $a_{k}$);
2611+
\end{dartCode}
2612+
\noindent{}where $C_q$ is obtained from $S_q$ by replacing occurrences of $S_N$,
2613+
which denote the superclass, by $N_C$, and $\SUPER_q$ is obtained from $S_q$ by
2614+
replacing occurrences of $S_N$ which denote the superclass by \SUPER{}}.
2615+
If $S_q$ is a generative const constructor, and $M$ does not declare any
2616+
fields, $C_q$ is also a const constructor.
2617+
2618+
\LMHash{}
2619+
For each generative constructor of the form \code{$S_q$($T_{1}$ $a_{1}$, \ldots , $T_{k}$ $a_{k}$, [$T_{k+1}$ $a_{k+1}$ = $d_1$, \ldots , $T_{k+p}$ $a_{k+p}$ = $d_p$])} of $S$ that is accessible to $L_C$, $C$ has an implicitly declared constructor of the form
2620+
\begin{dartCode}
2621+
$C_q$($T_{1}$ $a_{1}$, \ldots , $T_{k}$ $a_{k}$, [$T_{k+1}$ $a_{k+1}$ = $d'_{1}$, \ldots , $T_{k+p}$ $a_{k+p}$ = $d'_p$])
2622+
: $\SUPER_q$($a_{1}$, \ldots , $a_{k}$, $a_{k+1}$, \ldots, $a_p$);
2623+
\end{dartCode}
2624+
\noindent{}where $C_q$ is obtained from $S_q$ by replacing occurrences of $S_N$,
2625+
which denote the superclass, by $N_C$,
2626+
$\SUPER_q$ is obtained from $S_q$ by replacing occurrences of $S_N$
2627+
which denote the superclass by \SUPER{},
2628+
and $d'_i$, $i \in 1..p$, is a compile-time constant expression evaluating
2629+
to the same value as $d_i$.
2630+
If $S_q$ is a generative const constructor, and $M$ does not declare any
2631+
fields, $C_q$ is also a const constructor.
2632+
2633+
\LMHash{}
2634+
For each generative constructor of the form \code{$S_q$($T_{1}$ $a_{1}$, \ldots , $T_{k}$ $a_{k}$, \{$T_{k+1}$ $a_{k+1}$ = $d_1$, \ldots , $T_{k+n}$ $a_{k+n}$ = $d_n$\})} of $S$ that is accessible to $L_C$, $C$ has an implicitly declared constructor of the form
2635+
\begin{dartCode}
2636+
$C_q$($T_{1}$ $a_{1}$, \ldots , $T_{k}$ $a_{k}$, \{$T_{k+1}$ $a_{k+1}$ = $d'_1$, \ldots , $T_{k+n}$ $a_{k+n}$ = $d'_n$\})
2637+
: $\SUPER_q$($a_{1}$, \ldots , $a_{k}$, $a_{k+1}$: $a_{k+1}$, \ldots, $a_p$: $a_p$);
2638+
\end{dartCode}
2639+
\noindent{}where $C_q$ is obtained from $S_q$ by replacing occurrences of $S_N$
2640+
which denote the superclass by $N_C$,
2641+
$\SUPER_q$ is obtained from $S_q$ by replacing occurrences of $S_N$
2642+
which denote the superclass by \SUPER{}},
2643+
and $d'_i$, $i \in 1..n$, is a compile-time constant expression evaluating to the same value as $d_i$.
2644+
If $S_q$ is a generative const constructor, and $M$ does not declare any
2645+
fields, $C_q$ is also a const constructor.
26052646

26062647
\LMHash{}
2607-
If the mixin application declares support for interfaces, the resulting class implements those interfaces.
2648+
If the mixin application class declares interfaces, the resulting class also implements those interfaces.
26082649

26092650
\LMHash{}
26102651
It is a compile-time error if $S$ is an enumerated type (\ref{enums}) or a malformed type.
@@ -2621,7 +2662,7 @@ \subsection{Mixin Application}
26212662
}
26222663

26232664
\LMHash{}
2624-
The effect of a class definition of the form \code{\CLASS{} $C$ = $M$; } or the form \code{\CLASS{} $C$<$T_1, \ldots,\ T_n$> = $M$; } in library $L$ is to introduce the name $C$ into the scope of $L$, bound to the class (\ref{classes}) defined by the mixin application $M$.
2665+
The effect of a class definition of the form \code{\CLASS{} $C$ = $M$; } or the form \code{\CLASS{} $C<T_1, \ldots,\ T_n>$ = $M$; } in library $L$ is to introduce the name $C$ into the scope of $L$, bound to the class (\ref{classes}) defined by the mixin application $M$ for the name $C$.
26252666
The name of the class is also set to $C$.
26262667
If{}f the class is prefixed by the built-in identifier \ABSTRACT{}, the class being defined is an abstract class.
26272668

@@ -2649,11 +2690,11 @@ \subsection{Mixin Composition}
26492690

26502691
$M_1<T_1, \ldots, T_{k_{M_1}}> * M_2<U_1, \ldots, U_{k_{M_2}}>$
26512692

2652-
to $S<V_1, \ldots, V_{k_S}>$ is equivalent to
2693+
to $S<V_1, \ldots, V_{k_S}>$ for the name $C$ is equivalent to
26532694

26542695
\begin{dartCode}
2655-
\ABSTRACT{} \CLASS{} $Id_1<T_1, \ldots, T_{k_{M_1}}, U_1, \ldots, U_{k_{M_2}}, V_1, \ldots, V_{k_S}> = $
2656-
$Id_2<U_1, \ldots, U_{k_{M_2}}, V_1, \ldots, V_{k_S}>$ \WITH{} $M_1 <T_1, \ldots, T_{k_{M_1}}>$;
2696+
\ABSTRACT{} \CLASS{} $C<T_1, \ldots, T_{k_{M_1}}, U_1, \ldots, U_{k_{M_2}}, V_1, \ldots, V_{k_S}> = $
2697+
$Id_2<U_1, \ldots, U_{k_{M_2}}, V_1 \ldots V_{k_S}>$ \WITH{} $M_1 <T_1, \ldots, T_{k_{M_1}}>$;
26572698
\end{dartCode}
26582699

26592700
where $Id_2$ denotes
@@ -2663,10 +2704,10 @@ \subsection{Mixin Composition}
26632704
$S<V_1, \ldots, V_{k_S}>$ \WITH{} $M_2<U_1, \ldots, U_{k_{M_2}}>$;
26642705
\end{dartCode}
26652706

2666-
and $Id_1$ and $Id_2$ are unique identifiers that do not exist anywhere in the program.
2707+
and $Id_2$ is a unique identifier that does not exist anywhere in the program.
26672708

26682709
\rationale{
2669-
The classes produced by mixin composition are regarded as abstract because they cannot be instantiated independently.
2710+
The intermediate classes produced by mixin composition are regarded as abstract because they cannot be instantiated independently.
26702711
They are only introduced as anonymous superclasses of ordinary class declarations and mixin applications.
26712712
Consequently, no warning is given if a mixin composition includes abstract members, or incompletely implements an interface.
26722713
}
@@ -2676,7 +2717,7 @@ \subsection{Mixin Composition}
26762717

26772718
\commentary{
26782719
Note that any subset of $M_1$, $M_2$ and $S$ may or may not be generic.
2679-
For any non-generic declaration, the corresponding type parameters may be elided, and if no type parameters remain in the derived declarations $Id_1$ and/or $Id_2$ then the those declarations need not be generic either.
2720+
For any non-generic declaration, the corresponding type parameters may be elided, and if no type parameters remain in the derived declarations $C$ and/or $Id_2$ then the those declarations need not be generic either.
26802721
}
26812722

26822723

0 commit comments

Comments
 (0)