Skip to content

Commit 9282a34

Browse files
committed
Corrected specification of dynamic checks on redirecting factories
Change-Id: Ic044a003c73dea58539d090e82ab251f0d664efa Reviewed-on: https://dart-review.googlesource.com/71140 Reviewed-by: Lasse R.H. Nielsen <[email protected]>
1 parent a4b3009 commit 9282a34

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

docs/language/dartLangSpec.tex

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
% 2.1
2222
% - Remove 64-bit constraint on integer literals compiled to JavaScript numbers.
2323
% - Allow integer literals in a double context to evaluate to a double value.
24+
% - Specify dynamic error for a failing downcast in redirecting factory
25+
% constructor invocation.
26+
% - Specify that type arguments passed in a redirecting factory constructor
27+
% declaration must be taken into account during static checks.
2428
%
2529
% 2.0
2630
% - Don't allow functions as assert test values.
@@ -1645,6 +1649,23 @@ \subsection{Constructors}
16451649
A {\em constructor name} always begins with the name of its immediately enclosing class, and may optionally be followed by a dot and an identifier \id.
16461650
It is a compile-time error if the name of a constructor is not a constructor name.
16471651

1652+
\LMHash{}
1653+
The {\em function type of a constructor} $k$ is the function type whose
1654+
return type is the class that contains the declaration of $k$,
1655+
and whose formal parameter types, optionality, and names of named parameters
1656+
correspond to the declaration of $k$.
1657+
1658+
\commentary{
1659+
Note that the function type $F$ of a constructor $k$ may contain
1660+
type variables declared by the enclosing class $C$.
1661+
In that case we can apply a substitution to $F$, as in
1662+
$[T_1/X_1, \ldots, T_m/X_m]F$,
1663+
where $X_j, j \in 1 .. m$ are the formal type parameters of $C$
1664+
and $T_j, j \in 1 .. m$ are specified in the given context.
1665+
We may also omit such a substitution when the given context is
1666+
the instance scope of $C$, where $X_1, \ldots, X_m$ are in scope.
1667+
}
1668+
16481669
\commentary{
16491670
A constructor declaration may conflict with static member declarations
16501671
(\ref{classMemberConflicts}).
@@ -1801,8 +1822,8 @@ \subsubsection{Generative Constructors}
18011822

18021823
\LMHash{}
18031824
It is a dynamic error if an actual argument passed in an invocation of a redirecting generative constructor $k$
1804-
is not a subtype of the actual type
1805-
\ref{actualTypeOfADeclaration}) of the corresponding formal parameter in the declaration of $k$.
1825+
is not a subtype of the actual type (\ref{actualTypeOfADeclaration})
1826+
of the corresponding formal parameter in the declaration of $k$.
18061827
It is a dynamic error if an actual argument passed to the redirectee $k'$ of a redirecting generative constructor
18071828
is not a subtype of the actual type
18081829
(\ref{actualTypeOfADeclaration}) of the corresponding formal parameter in the declaration of the redirectee.
@@ -2062,10 +2083,6 @@ \subsubsection{Factories}
20622083
or it would amount to a dynamic error which is simply delayed a single step.
20632084
}
20642085

2065-
\LMHash{}
2066-
Moreover, when $\ConstMetavar$ is \CONST{}
2067-
the redirectee must be a constant constructor.
2068-
20692086
\commentary{
20702087
Note that the non-generic case is covered by letting $m$ or $p$ or both be zero,
20712088
in which case the formal type parameter list of the class $C$
@@ -2079,6 +2096,11 @@ \subsubsection{Factories}
20792096
Hence, default values are disallowed.
20802097
}
20812098

2099+
\LMHash{}
2100+
It is a compile-time error if a formal parameter of $k'$ has a default value
2101+
whose type is not a subtype of the type annotation
2102+
on the corresponding formal parameter in $k$.
2103+
20822104
\LMHash{}
20832105
It is a compile-time error if a redirecting factory constructor redirects to itself, either directly or indirectly via a sequence of redirections.
20842106

@@ -2128,10 +2150,19 @@ \subsubsection{Factories}
21282150
It is a compile-time error if $k$ is prefixed with the \CONST{} modifier but $k'$ is not a constant constructor (\ref{constantConstructors}).
21292151

21302152
\LMHash{}
2131-
It is a compile-time error if the function type of $k'$ is not a subtype of the type of $k$.
2153+
Let $T_1, \ldots, T_m$ be the actual type arguments passed to $k'$
2154+
in the declaration of $k$.
2155+
Let $X_1, \ldots, X_m$ be the formal type arguments declared by
2156+
the class that contains the declaration of $k'$.
2157+
Let $F'$ be the function of $k'$ (\ref{constructors}).
2158+
It is a compile-time error if $[T_1/X_1, \ldots, T_m/X_m]F'$
2159+
is not a subtype of the function type of $k$.
21322160

21332161
\commentary{
2134-
This implies that the resulting object conforms to the interface of the immediately enclosing class of $k$.
2162+
In the case where the two classes are non-generic
2163+
this is just a subtype check on the function types of the two constructors.
2164+
In general, this implies that the resulting object conforms to
2165+
the interface of the immediately enclosing class of $k$.
21352166
}
21362167

21372168
\LMHash{}
@@ -2142,6 +2173,11 @@ \subsubsection{Factories}
21422173
assume that $k$ is a redirecting factory constructor
21432174
and $k'$ is the redirectee of $k$.
21442175

2176+
\LMHash{}
2177+
It is a dynamic error if an actual argument passed in an invocation of $k$
2178+
is not a subtype of the actual type (\ref{actualTypeOfADeclaration})
2179+
of the corresponding formal parameter in the declaration of $k$.
2180+
21452181
\LMHash{}
21462182
When the redirectee $k'$ is a factory constructor,
21472183
execution of $k$ amounts to execution of $k'$ with the actual arguments passed to $k$.

0 commit comments

Comments
 (0)