@@ -23323,7 +23323,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2332323323 \DefEquals{\UpperBoundType{$T_1$}{$T_2$}}{T_2},
2332423324 if \SubtypeNE{T_1}{T_2}.
2332523325
23326- \commentary{
23326+ \commentary{%
2332723327 In this and in the following cases, both types must be interface types.%
2332823328 }
2332923329\item
@@ -23580,7 +23580,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2358023580 \DefEquals{\LowerBoundType{$T_1$}{$T_2$}}{\code{Never}}, otherwise.
2358123581\end{itemize}
2358223582
23583- \rationale{
23583+ \rationale{%
2358423584The rules defining \UpperBoundTypeName{} and \LowerBoundTypeName{}
2358523585are somewhat redundant in that they explicitly specify
2358623586a lot of pairs of symmetric cases.
@@ -25372,6 +25372,7 @@ \subsection{Type Promotion}
2537225372}
2537325373
2537425374\LMHash{}%
25375+ \BlindDefineSymbol{\ell, v}%
2537525376Let $\ell$ be a location,
2537625377and let $v$ be a local variable which is in scope at $\ell$.
2537725378Assume that $\ell$ occurs after the declaration of $v$.
@@ -25395,34 +25396,33 @@ \subsection{Type Promotion}
2539525396
2539625397\LMHash{}%
2539725398In particular,
25398- a check of the form \code{$v$\,\,==\,\,\NULL},
25399- \code{\NULL\,\,==\,\,$v$},
25400- or \code{$v$\,\,\IS\,\,Null}
25399+ an expression of the form \code{$v$\,\,==\,\,\NULL} or
25400+ \code{\NULL\,\,==\,\,$v$}
2540125401where $v$ has type $T$ at $\ell$
2540225402promotes the type of $v$
25403- to \code{Null} in the \TRUE{} continuation,
25404- and to \NonNullType{$T$} in the \FALSE{} continuation.
25405-
25406- %% TODO(eernst), for review: The null safety spec says that `T?` is
25407- %% promoted to `T`, but implementations _do_ promote `X extends int?` to
25408- %% `X & int`. So we may be able to specify something which will yield
25409- %% slightly more precise types, and which is more precisely the implemented
25410- %% behavior.
25411- \LMHash{}%
25412- A check of the form \code{$v$\,\,!=\,\,\NULL},
25413- \code{\NULL\,\,!=\,\,$v$},
25414- or \code{$v$\,\,\IS\,\,$T$}
25415- where $v$ has static type $T?$ at $\ell$
25403+ to \NonNullType{$T$} in the \FALSE{} continuation;
25404+ and an expression of the form \code{$v$\,\,!=\,\,\NULL} or
25405+ \code{\NULL\,\,!=\,\,$v$}
25406+ where $v$ has static type $T$ at $\ell$
25407+ promotes the type of $v$
25408+ to \NonNullType{$T$} in the \TRUE{} continuation.
25409+
25410+ \LMHash{}%
25411+ Similarly, a type test of the form \code{$v$\,\,\IS\,\,$T$}
2541625412promotes the type of $v$
2541725413to $T$ in the \TRUE{} continuation,
25418- and to \code{Null} in the \FALSE{} continuation.
25414+ and a type check of the form \code{$v$\,\,\AS\,\,$T$}
25415+ promotes the type of $v$
25416+ to $T$ in the continuation where the expression evaluated to an object
25417+ (\commentary{that is, it did not throw}).
2541925418
2542025419\commentary{%
2542125420The resulting type of $v$ may be the obvious one, e.g.,
2542225421\code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
2542325422but it may also give rise to a demotion
25424- (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
25425- and it may have no effect on the type of $v$
25423+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$
25424+ and potentially promoting it to some other type of interest).
25425+ It may also have no effect on the type of $v$
2542625426(e.g., when the static type of $e$ is not a type of interest).
2542725427These details will be specified in a future version of this specification.
2542825428
@@ -25602,15 +25602,20 @@ \section*{Appendix: Algorithmic Subtyping}
2560225602the one which is specified in Fig.~\ref{fig:subtypeRules}.
2560325603It shows that Dart subtyping relationships can be decided
2560425604with good performance.
25605+ This section is not normative.
2560525606
2560625607\LMHash{}%
2560725608In this algorithm, types are considered to be the same when they have
2560825609the same canonical syntax
2560925610(\ref{theCanonicalSyntaxOfTypes}).
25611+ \commentary{%
25612+ For example, \SubtypeStd{\code{C}}{\code{C}} does not hold if
25613+ the two occurrences of \code{C} refer to declarations in different libraries.%
25614+ }
2561025615The algorithm must be performed such that the first case that matches
2561125616is always the case which is performed.
2561225617The algorithm produces results which are both positive and negative
25613- (\commentary{
25618+ (\commentary{%
2561425619 that is, in some situations the subtype relation is determined to be false%
2561525620}),
2561625621which is important for performance because
@@ -25622,16 +25627,18 @@ \section*{Appendix: Algorithmic Subtyping}
2562225627\begin{itemize}
2562325628\item
2562425629 \textbf{Reflexivity:}
25625- if $T_0$ and $T_1$ are the same type then \SubtypeNE{T_0}{T_1}
25630+ if $T_0$ and $T_1$ are the same atomic type then \SubtypeNE{T_0}{T_1}.
2562625631
2562725632 \commentary{%
25628- Note that this check is necessary as the base case for primitive types,
25633+ This check is necessary as the base case for primitive types,
2562925634 and type variables, but not for composite types.
2563025635 In particular, a structural equality check is admissible,
2563125636 but not required here.
25632- Pragmatically, non-constant time identity checks here are
25633- counter-productive.
25634- So this rule should only be used when $T$ is atomic.%
25637+ Non-constant time identity checks here are counter-productive
25638+ because the following rules will yield the same result anyway,
25639+ so we may just perform a full traversal of a large structure twice
25640+ for no reason.
25641+ Hence, this rule is only used when the given type is atomic.%
2563525642 }
2563625643\item
2563725644 \textbf{Right Top:}
@@ -25641,7 +25648,7 @@ \section*{Appendix: Algorithmic Subtyping}
2564125648 if $T_0$ is \DYNAMIC{} or \VOID{}
2564225649 then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
2564325650\item
25644- \textbf{Left Bottom:}
25651+ \textbf{Bottom:}
2564525652 if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
2564625653\item
2564725654 \textbf{Right Object:}
@@ -25694,7 +25701,7 @@ \section*{Appendix: Algorithmic Subtyping}
2569425701 or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
2569525702 then \SubtypeNE{T_0}{T_1}.
2569625703
25697- \commentary{
25704+ \commentary{%
2569825705 Note that this rule is admissible, and can be safely elided if desired.%
2569925706 }
2570025707\item
@@ -25777,7 +25784,7 @@ \section*{Appendix: Algorithmic Subtyping}
2577725784 for $i \in 0 .. q$.
2577825785 \item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
2577925786 \item $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
25780- have the same canonical syntax , for $i \in 0 .. k$.
25787+ are subtypes of each other , for $i \in 0 .. k$.
2578125788 \end{itemize}
2578225789\item
2578325790 \textbf{Named Function Types:}
@@ -25818,8 +25825,7 @@ \section*{Appendix: Algorithmic Subtyping}
2581825825 \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
2581925826 \item
2582025827 $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
25821- have the same canonical syntax,
25822- for each $i \in 0 .. k$.
25828+ are subtypes of each other, for each $i \in 0 .. k$.
2582325829 \end{itemize}
2582425830
2582525831 \commentary{%
0 commit comments