@@ -23600,7 +23600,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2360023600 \DefEquals{\UpperBoundType{$T_1$}{$T_2$}}{T_2},
2360123601 if \SubtypeNE{T_1}{T_2}.
2360223602
23603- \commentary{
23603+ \commentary{%
2360423604 In this and in the following cases, both types must be interface types.%
2360523605 }
2360623606\item
@@ -23857,7 +23857,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2385723857 \DefEquals{\LowerBoundType{$T_1$}{$T_2$}}{\code{Never}}, otherwise.
2385823858\end{itemize}
2385923859
23860- \rationale{
23860+ \rationale{%
2386123861The rules defining \UpperBoundTypeName{} and \LowerBoundTypeName{}
2386223862are somewhat redundant in that they explicitly specify
2386323863a lot of pairs of symmetric cases.
@@ -25675,6 +25675,7 @@ \subsection{Type Promotion}
2567525675}
2567625676
2567725677\LMHash{}%
25678+ \BlindDefineSymbol{\ell, v}%
2567825679Let $\ell$ be a location,
2567925680and let $v$ be a local variable which is in scope at $\ell$.
2568025681Assume that $\ell$ occurs after the declaration of $v$.
@@ -25698,34 +25699,33 @@ \subsection{Type Promotion}
2569825699
2569925700\LMHash{}%
2570025701In particular,
25701- a check of the form \code{$v$\,\,==\,\,\NULL},
25702- \code{\NULL\,\,==\,\,$v$},
25703- or \code{$v$\,\,\IS\,\,Null}
25702+ an expression of the form \code{$v$\,\,==\,\,\NULL} or
25703+ \code{\NULL\,\,==\,\,$v$}
2570425704where $v$ has type $T$ at $\ell$
2570525705promotes the type of $v$
25706- to \code{Null} in the \TRUE{} continuation,
25707- and to \NonNullType{$T$} in the \FALSE{} continuation.
25708-
25709- %% TODO(eernst), for review: The null safety spec says that `T?` is
25710- %% promoted to `T`, but implementations _do_ promote `X extends int?` to
25711- %% `X & int`. So we may be able to specify something which will yield
25712- %% slightly more precise types, and which is more precisely the implemented
25713- %% behavior.
25714- \LMHash{}%
25715- A check of the form \code{$v$\,\,!=\,\,\NULL},
25716- \code{\NULL\,\,!=\,\,$v$},
25717- or \code{$v$\,\,\IS\,\,$T$}
25718- where $v$ has static type $T?$ at $\ell$
25706+ to \NonNullType{$T$} in the \FALSE{} continuation;
25707+ and an expression of the form \code{$v$\,\,!=\,\,\NULL} or
25708+ \code{\NULL\,\,!=\,\,$v$}
25709+ where $v$ has static type $T$ at $\ell$
25710+ promotes the type of $v$
25711+ to \NonNullType{$T$} in the \TRUE{} continuation.
25712+
25713+ \LMHash{}%
25714+ Similarly, a type test of the form \code{$v$\,\,\IS\,\,$T$}
2571925715promotes the type of $v$
2572025716to $T$ in the \TRUE{} continuation,
25721- and to \code{Null} in the \FALSE{} continuation.
25717+ and a type check of the form \code{$v$\,\,\AS\,\,$T$}
25718+ promotes the type of $v$
25719+ to $T$ in the continuation where the expression evaluated to an object
25720+ (\commentary{that is, it did not throw}).
2572225721
2572325722\commentary{%
2572425723 The resulting type of $v$ may be the obvious one, e.g.,
2572525724 \code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
2572625725 but it may also give rise to a demotion
25727- (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
25728- and it may have no effect on the type of $v$
25726+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$
25727+ and potentially promoting it to some other type of interest).
25728+ It may also have no effect on the type of $v$
2572925729 (e.g., when the static type of $e$ is not a type of interest).
2573025730 These details will be specified in a future version of this specification.
2573125731
@@ -25880,15 +25880,20 @@ \section*{Appendix: Algorithmic Subtyping}
2588025880the one which is specified in Fig.~\ref{fig:subtypeRules}.
2588125881It shows that Dart subtyping relationships can be decided
2588225882with good performance.
25883+ This section is not normative.
2588325884
2588425885\LMHash{}%
2588525886In this algorithm, types are considered to be the same when they have
2588625887the same canonical syntax
2588725888(\ref{theCanonicalSyntaxOfTypes}).
25889+ \commentary{%
25890+ For example, \SubtypeStd{\code{C}}{\code{C}} does not hold if
25891+ the two occurrences of \code{C} refer to declarations in different libraries.%
25892+ }
2588825893The algorithm must be performed such that the first case that matches
2588925894is always the case which is performed.
2589025895The algorithm produces results which are both positive and negative
25891- (\commentary{
25896+ (\commentary{%
2589225897 that is, in some situations the subtype relation is determined to be false%
2589325898}),
2589425899which is important for performance because
@@ -25900,16 +25905,18 @@ \section*{Appendix: Algorithmic Subtyping}
2590025905\begin{itemize}
2590125906\item
2590225907 \textbf{Reflexivity:}
25903- if $T_0$ and $T_1$ are the same type then \SubtypeNE{T_0}{T_1}
25908+ if $T_0$ and $T_1$ are the same atomic type then \SubtypeNE{T_0}{T_1}.
2590425909
2590525910 \commentary{%
25906- Note that this check is necessary as the base case for primitive types,
25911+ This check is necessary as the base case for primitive types,
2590725912 and type variables, but not for composite types.
2590825913 In particular, a structural equality check is admissible,
2590925914 but not required here.
25910- Pragmatically, non-constant time identity checks here are
25911- counter-productive.
25912- So this rule should only be used when $T$ is atomic.%
25915+ Non-constant time identity checks here are counter-productive
25916+ because the following rules will yield the same result anyway,
25917+ so we may just perform a full traversal of a large structure twice
25918+ for no reason.
25919+ Hence, this rule is only used when the given type is atomic.%
2591325920 }
2591425921\item
2591525922 \textbf{Right Top:}
@@ -25919,7 +25926,7 @@ \section*{Appendix: Algorithmic Subtyping}
2591925926 if $T_0$ is \DYNAMIC{} or \VOID{}
2592025927 then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
2592125928\item
25922- \textbf{Left Bottom:}
25929+ \textbf{Bottom:}
2592325930 if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
2592425931\item
2592525932 \textbf{Right Object:}
@@ -25972,7 +25979,7 @@ \section*{Appendix: Algorithmic Subtyping}
2597225979 or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
2597325980 then \SubtypeNE{T_0}{T_1}.
2597425981
25975- \commentary{
25982+ \commentary{%
2597625983 Note that this rule is admissible, and can be safely elided if desired.%
2597725984 }
2597825985\item
@@ -26055,7 +26062,7 @@ \section*{Appendix: Algorithmic Subtyping}
2605526062 for $i \in 0 .. q$.
2605626063 \item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
2605726064 \item $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
26058- have the same canonical syntax , for $i \in 0 .. k$.
26065+ are subtypes of each other , for $i \in 0 .. k$.
2605926066 \end{itemize}
2606026067\item
2606126068 \textbf{Named Function Types:}
@@ -26096,8 +26103,7 @@ \section*{Appendix: Algorithmic Subtyping}
2609626103 \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
2609726104 \item
2609826105 $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
26099- have the same canonical syntax,
26100- for each $i \in 0 .. k$.
26106+ are subtypes of each other, for each $i \in 0 .. k$.
2610126107 \end{itemize}
2610226108
2610326109 \commentary{%
0 commit comments