@@ -23548,7 +23548,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23548
23548
\DefEquals{\UpperBoundType{$T_1$}{$T_2$}}{T_2},
23549
23549
if \SubtypeNE{T_1}{T_2}.
23550
23550
23551
- \commentary{
23551
+ \commentary{%
23552
23552
In this and in the following cases, both types must be interface types.%
23553
23553
}
23554
23554
\item
@@ -23805,7 +23805,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23805
23805
\DefEquals{\LowerBoundType{$T_1$}{$T_2$}}{\code{Never}}, otherwise.
23806
23806
\end{itemize}
23807
23807
23808
- \rationale{
23808
+ \rationale{%
23809
23809
The rules defining \UpperBoundTypeName{} and \LowerBoundTypeName{}
23810
23810
are somewhat redundant in that they explicitly specify
23811
23811
a lot of pairs of symmetric cases.
@@ -25623,6 +25623,7 @@ \subsection{Type Promotion}
25623
25623
}
25624
25624
25625
25625
\LMHash{}%
25626
+ \BlindDefineSymbol{\ell, v}%
25626
25627
Let $\ell$ be a location,
25627
25628
and let $v$ be a local variable which is in scope at $\ell$.
25628
25629
Assume that $\ell$ occurs after the declaration of $v$.
@@ -25646,34 +25647,33 @@ \subsection{Type Promotion}
25646
25647
25647
25648
\LMHash{}%
25648
25649
In particular,
25649
- a check of the form \code{$v$\,\,==\,\,\NULL},
25650
- \code{\NULL\,\,==\,\,$v$},
25651
- or \code{$v$\,\,\IS\,\,Null}
25650
+ an expression of the form \code{$v$\,\,==\,\,\NULL} or
25651
+ \code{\NULL\,\,==\,\,$v$}
25652
25652
where $v$ has type $T$ at $\ell$
25653
25653
promotes the type of $v$
25654
- to \code{Null} in the \TRUE{} continuation,
25655
- and to \NonNullType{$T$} in the \FALSE{} continuation.
25656
-
25657
- %% TODO(eernst), for review: The null safety spec says that `T?` is
25658
- %% promoted to `T`, but implementations _do_ promote `X extends int?` to
25659
- %% `X & int`. So we may be able to specify something which will yield
25660
- %% slightly more precise types, and which is more precisely the implemented
25661
- %% behavior.
25662
- \LMHash{}%
25663
- A check of the form \code{$v$\,\,!=\,\,\NULL},
25664
- \code{\NULL\,\,!=\,\,$v$},
25665
- or \code{$v$\,\,\IS\,\,$T$}
25666
- where $v$ has static type $T?$ at $\ell$
25654
+ to \NonNullType{$T$} in the \FALSE{} continuation;
25655
+ and an expression of the form \code{$v$\,\,!=\,\,\NULL} or
25656
+ \code{\NULL\,\,!=\,\,$v$}
25657
+ where $v$ has static type $T$ at $\ell$
25658
+ promotes the type of $v$
25659
+ to \NonNullType{$T$} in the \TRUE{} continuation.
25660
+
25661
+ \LMHash{}%
25662
+ Similarly, a type test of the form \code{$v$\,\,\IS\,\,$T$}
25667
25663
promotes the type of $v$
25668
25664
to $T$ in the \TRUE{} continuation,
25669
- and to \code{Null} in the \FALSE{} continuation.
25665
+ and a type check of the form \code{$v$\,\,\AS\,\,$T$}
25666
+ promotes the type of $v$
25667
+ to $T$ in the continuation where the expression evaluated to an object
25668
+ (\commentary{that is, it did not throw}).
25670
25669
25671
25670
\commentary{%
25672
25671
The resulting type of $v$ may be the obvious one, e.g.,
25673
25672
\code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
25674
25673
but it may also give rise to a demotion
25675
- (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
25676
- and it may have no effect on the type of $v$
25674
+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$
25675
+ and potentially promoting it to some other type of interest).
25676
+ It may also have no effect on the type of $v$
25677
25677
(e.g., when the static type of $e$ is not a type of interest).
25678
25678
These details will be specified in a future version of this specification.
25679
25679
@@ -25853,15 +25853,20 @@ \section*{Appendix: Algorithmic Subtyping}
25853
25853
the one which is specified in Fig.~\ref{fig:subtypeRules}.
25854
25854
It shows that Dart subtyping relationships can be decided
25855
25855
with good performance.
25856
+ This section is not normative.
25856
25857
25857
25858
\LMHash{}%
25858
25859
In this algorithm, types are considered to be the same when they have
25859
25860
the same canonical syntax
25860
25861
(\ref{theCanonicalSyntaxOfTypes}).
25862
+ \commentary{%
25863
+ For example, \SubtypeStd{\code{C}}{\code{C}} does not hold if
25864
+ the two occurrences of \code{C} refer to declarations in different libraries.%
25865
+ }
25861
25866
The algorithm must be performed such that the first case that matches
25862
25867
is always the case which is performed.
25863
25868
The algorithm produces results which are both positive and negative
25864
- (\commentary{
25869
+ (\commentary{%
25865
25870
that is, in some situations the subtype relation is determined to be false%
25866
25871
}),
25867
25872
which is important for performance because
@@ -25873,16 +25878,18 @@ \section*{Appendix: Algorithmic Subtyping}
25873
25878
\begin{itemize}
25874
25879
\item
25875
25880
\textbf{Reflexivity:}
25876
- if $T_0$ and $T_1$ are the same type then \SubtypeNE{T_0}{T_1}
25881
+ if $T_0$ and $T_1$ are the same atomic type then \SubtypeNE{T_0}{T_1}.
25877
25882
25878
25883
\commentary{%
25879
- Note that this check is necessary as the base case for primitive types,
25884
+ This check is necessary as the base case for primitive types,
25880
25885
and type variables, but not for composite types.
25881
25886
In particular, a structural equality check is admissible,
25882
25887
but not required here.
25883
- Pragmatically, non-constant time identity checks here are
25884
- counter-productive.
25885
- So this rule should only be used when $T$ is atomic.%
25888
+ Non-constant time identity checks here are counter-productive
25889
+ because the following rules will yield the same result anyway,
25890
+ so we may just perform a full traversal of a large structure twice
25891
+ for no reason.
25892
+ Hence, this rule is only used when the given type is atomic.%
25886
25893
}
25887
25894
\item
25888
25895
\textbf{Right Top:}
@@ -25892,7 +25899,7 @@ \section*{Appendix: Algorithmic Subtyping}
25892
25899
if $T_0$ is \DYNAMIC{} or \VOID{}
25893
25900
then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
25894
25901
\item
25895
- \textbf{Left Bottom:}
25902
+ \textbf{Bottom:}
25896
25903
if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
25897
25904
\item
25898
25905
\textbf{Right Object:}
@@ -25945,7 +25952,7 @@ \section*{Appendix: Algorithmic Subtyping}
25945
25952
or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
25946
25953
then \SubtypeNE{T_0}{T_1}.
25947
25954
25948
- \commentary{
25955
+ \commentary{%
25949
25956
Note that this rule is admissible, and can be safely elided if desired.%
25950
25957
}
25951
25958
\item
@@ -26028,7 +26035,7 @@ \section*{Appendix: Algorithmic Subtyping}
26028
26035
for $i \in 0 .. q$.
26029
26036
\item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
26030
26037
\item $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
26031
- have the same canonical syntax , for $i \in 0 .. k$.
26038
+ are subtypes of each other , for $i \in 0 .. k$.
26032
26039
\end{itemize}
26033
26040
\item
26034
26041
\textbf{Named Function Types:}
@@ -26069,8 +26076,7 @@ \section*{Appendix: Algorithmic Subtyping}
26069
26076
\SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
26070
26077
\item
26071
26078
$B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
26072
- have the same canonical syntax,
26073
- for each $i \in 0 .. k$.
26079
+ are subtypes of each other, for each $i \in 0 .. k$.
26074
26080
\end{itemize}
26075
26081
26076
26082
\commentary{%
0 commit comments