@@ -23536,7 +23536,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23536
23536
\DefEquals{\UpperBoundType{$T_1$}{$T_2$}}{T_2},
23537
23537
if \SubtypeNE{T_1}{T_2}.
23538
23538
23539
- \commentary{
23539
+ \commentary{%
23540
23540
In this and in the following cases, both types must be interface types.%
23541
23541
}
23542
23542
\item
@@ -23793,7 +23793,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23793
23793
\DefEquals{\LowerBoundType{$T_1$}{$T_2$}}{\code{Never}}, otherwise.
23794
23794
\end{itemize}
23795
23795
23796
- \rationale{
23796
+ \rationale{%
23797
23797
The rules defining \UpperBoundTypeName{} and \LowerBoundTypeName{}
23798
23798
are somewhat redundant in that they explicitly specify
23799
23799
a lot of pairs of symmetric cases.
@@ -25611,6 +25611,7 @@ \subsection{Type Promotion}
25611
25611
}
25612
25612
25613
25613
\LMHash{}%
25614
+ \BlindDefineSymbol{\ell, v}%
25614
25615
Let $\ell$ be a location,
25615
25616
and let $v$ be a local variable which is in scope at $\ell$.
25616
25617
Assume that $\ell$ occurs after the declaration of $v$.
@@ -25634,34 +25635,33 @@ \subsection{Type Promotion}
25634
25635
25635
25636
\LMHash{}%
25636
25637
In particular,
25637
- a check of the form \code{$v$\,\,==\,\,\NULL},
25638
- \code{\NULL\,\,==\,\,$v$},
25639
- or \code{$v$\,\,\IS\,\,Null}
25638
+ an expression of the form \code{$v$\,\,==\,\,\NULL} or
25639
+ \code{\NULL\,\,==\,\,$v$}
25640
25640
where $v$ has type $T$ at $\ell$
25641
25641
promotes the type of $v$
25642
- to \code{Null} in the \TRUE{} continuation,
25643
- and to \NonNullType{$T$} in the \FALSE{} continuation.
25644
-
25645
- %% TODO(eernst), for review: The null safety spec says that `T?` is
25646
- %% promoted to `T`, but implementations _do_ promote `X extends int?` to
25647
- %% `X & int`. So we may be able to specify something which will yield
25648
- %% slightly more precise types, and which is more precisely the implemented
25649
- %% behavior.
25650
- \LMHash{}%
25651
- A check of the form \code{$v$\,\,!=\,\,\NULL},
25652
- \code{\NULL\,\,!=\,\,$v$},
25653
- or \code{$v$\,\,\IS\,\,$T$}
25654
- where $v$ has static type $T?$ at $\ell$
25642
+ to \NonNullType{$T$} in the \FALSE{} continuation;
25643
+ and an expression of the form \code{$v$\,\,!=\,\,\NULL} or
25644
+ \code{\NULL\,\,!=\,\,$v$}
25645
+ where $v$ has static type $T$ at $\ell$
25646
+ promotes the type of $v$
25647
+ to \NonNullType{$T$} in the \TRUE{} continuation.
25648
+
25649
+ \LMHash{}%
25650
+ Similarly, a type test of the form \code{$v$\,\,\IS\,\,$T$}
25655
25651
promotes the type of $v$
25656
25652
to $T$ in the \TRUE{} continuation,
25657
- and to \code{Null} in the \FALSE{} continuation.
25653
+ and a type check of the form \code{$v$\,\,\AS\,\,$T$}
25654
+ promotes the type of $v$
25655
+ to $T$ in the continuation where the expression evaluated to an object
25656
+ (\commentary{that is, it did not throw}).
25658
25657
25659
25658
\commentary{%
25660
25659
The resulting type of $v$ may be the obvious one, e.g.,
25661
25660
\code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
25662
25661
but it may also give rise to a demotion
25663
- (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
25664
- and it may have no effect on the type of $v$
25662
+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$
25663
+ and potentially promoting it to some other type of interest).
25664
+ It may also have no effect on the type of $v$
25665
25665
(e.g., when the static type of $e$ is not a type of interest).
25666
25666
These details will be specified in a future version of this specification.
25667
25667
@@ -25841,15 +25841,20 @@ \section*{Appendix: Algorithmic Subtyping}
25841
25841
the one which is specified in Fig.~\ref{fig:subtypeRules}.
25842
25842
It shows that Dart subtyping relationships can be decided
25843
25843
with good performance.
25844
+ This section is not normative.
25844
25845
25845
25846
\LMHash{}%
25846
25847
In this algorithm, types are considered to be the same when they have
25847
25848
the same canonical syntax
25848
25849
(\ref{theCanonicalSyntaxOfTypes}).
25850
+ \commentary{%
25851
+ For example, \SubtypeStd{\code{C}}{\code{C}} does not hold if
25852
+ the two occurrences of \code{C} refer to declarations in different libraries.%
25853
+ }
25849
25854
The algorithm must be performed such that the first case that matches
25850
25855
is always the case which is performed.
25851
25856
The algorithm produces results which are both positive and negative
25852
- (\commentary{
25857
+ (\commentary{%
25853
25858
that is, in some situations the subtype relation is determined to be false%
25854
25859
}),
25855
25860
which is important for performance because
@@ -25861,16 +25866,18 @@ \section*{Appendix: Algorithmic Subtyping}
25861
25866
\begin{itemize}
25862
25867
\item
25863
25868
\textbf{Reflexivity:}
25864
- if $T_0$ and $T_1$ are the same type then \SubtypeNE{T_0}{T_1}
25869
+ if $T_0$ and $T_1$ are the same atomic type then \SubtypeNE{T_0}{T_1}.
25865
25870
25866
25871
\commentary{%
25867
- Note that this check is necessary as the base case for primitive types,
25872
+ This check is necessary as the base case for primitive types,
25868
25873
and type variables, but not for composite types.
25869
25874
In particular, a structural equality check is admissible,
25870
25875
but not required here.
25871
- Pragmatically, non-constant time identity checks here are
25872
- counter-productive.
25873
- So this rule should only be used when $T$ is atomic.%
25876
+ Non-constant time identity checks here are counter-productive
25877
+ because the following rules will yield the same result anyway,
25878
+ so we may just perform a full traversal of a large structure twice
25879
+ for no reason.
25880
+ Hence, this rule is only used when the given type is atomic.%
25874
25881
}
25875
25882
\item
25876
25883
\textbf{Right Top:}
@@ -25880,7 +25887,7 @@ \section*{Appendix: Algorithmic Subtyping}
25880
25887
if $T_0$ is \DYNAMIC{} or \VOID{}
25881
25888
then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
25882
25889
\item
25883
- \textbf{Left Bottom:}
25890
+ \textbf{Bottom:}
25884
25891
if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
25885
25892
\item
25886
25893
\textbf{Right Object:}
@@ -25933,7 +25940,7 @@ \section*{Appendix: Algorithmic Subtyping}
25933
25940
or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
25934
25941
then \SubtypeNE{T_0}{T_1}.
25935
25942
25936
- \commentary{
25943
+ \commentary{%
25937
25944
Note that this rule is admissible, and can be safely elided if desired.%
25938
25945
}
25939
25946
\item
@@ -26016,7 +26023,7 @@ \section*{Appendix: Algorithmic Subtyping}
26016
26023
for $i \in 0 .. q$.
26017
26024
\item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
26018
26025
\item $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
26019
- have the same canonical syntax , for $i \in 0 .. k$.
26026
+ are subtypes of each other , for $i \in 0 .. k$.
26020
26027
\end{itemize}
26021
26028
\item
26022
26029
\textbf{Named Function Types:}
@@ -26057,8 +26064,7 @@ \section*{Appendix: Algorithmic Subtyping}
26057
26064
\SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
26058
26065
\item
26059
26066
$B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
26060
- have the same canonical syntax,
26061
- for each $i \in 0 .. k$.
26067
+ are subtypes of each other, for each $i \in 0 .. k$.
26062
26068
\end{itemize}
26063
26069
26064
26070
\commentary{%
0 commit comments