@@ -23522,7 +23522,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23522
23522
\DefEquals{\UpperBoundType{$T_1$}{$T_2$}}{T_2},
23523
23523
if \SubtypeNE{T_1}{T_2}.
23524
23524
23525
- \commentary{
23525
+ \commentary{%
23526
23526
In this and in the following cases, both types must be interface types.%
23527
23527
}
23528
23528
\item
@@ -23779,7 +23779,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23779
23779
\DefEquals{\LowerBoundType{$T_1$}{$T_2$}}{\code{Never}}, otherwise.
23780
23780
\end{itemize}
23781
23781
23782
- \rationale{
23782
+ \rationale{%
23783
23783
The rules defining \UpperBoundTypeName{} and \LowerBoundTypeName{}
23784
23784
are somewhat redundant in that they explicitly specify
23785
23785
a lot of pairs of symmetric cases.
@@ -25583,6 +25583,7 @@ \subsection{Type Promotion}
25583
25583
}
25584
25584
25585
25585
\LMHash{}%
25586
+ \BlindDefineSymbol{\ell, v}%
25586
25587
Let $\ell$ be a location,
25587
25588
and let $v$ be a local variable which is in scope at $\ell$.
25588
25589
Assume that $\ell$ occurs after the declaration of $v$.
@@ -25606,34 +25607,33 @@ \subsection{Type Promotion}
25606
25607
25607
25608
\LMHash{}%
25608
25609
In particular,
25609
- a check of the form \code{$v$\,\,==\,\,\NULL},
25610
- \code{\NULL\,\,==\,\,$v$},
25611
- or \code{$v$\,\,\IS\,\,Null}
25610
+ an expression of the form \code{$v$\,\,==\,\,\NULL} or
25611
+ \code{\NULL\,\,==\,\,$v$}
25612
25612
where $v$ has type $T$ at $\ell$
25613
25613
promotes the type of $v$
25614
- to \code{Null} in the \TRUE{} continuation,
25615
- and to \NonNullType{$T$} in the \FALSE{} continuation.
25616
-
25617
- %% TODO(eernst), for review: The null safety spec says that `T?` is
25618
- %% promoted to `T`, but implementations _do_ promote `X extends int?` to
25619
- %% `X & int`. So we may be able to specify something which will yield
25620
- %% slightly more precise types, and which is more precisely the implemented
25621
- %% behavior.
25622
- \LMHash{}%
25623
- A check of the form \code{$v$\,\,!=\,\,\NULL},
25624
- \code{\NULL\,\,!=\,\,$v$},
25625
- or \code{$v$\,\,\IS\,\,$T$}
25626
- where $v$ has static type $T?$ at $\ell$
25614
+ to \NonNullType{$T$} in the \FALSE{} continuation;
25615
+ and an expression of the form \code{$v$\,\,!=\,\,\NULL} or
25616
+ \code{\NULL\,\,!=\,\,$v$}
25617
+ where $v$ has static type $T$ at $\ell$
25618
+ promotes the type of $v$
25619
+ to \NonNullType{$T$} in the \TRUE{} continuation.
25620
+
25621
+ \LMHash{}%
25622
+ Similarly, a type test of the form \code{$v$\,\,\IS\,\,$T$}
25627
25623
promotes the type of $v$
25628
25624
to $T$ in the \TRUE{} continuation,
25629
- and to \code{Null} in the \FALSE{} continuation.
25625
+ and a type check of the form \code{$v$\,\,\AS\,\,$T$}
25626
+ promotes the type of $v$
25627
+ to $T$ in the continuation where the expression evaluated to an object
25628
+ (\commentary{that is, it did not throw}).
25630
25629
25631
25630
\commentary{%
25632
25631
The resulting type of $v$ may be the obvious one, e.g.,
25633
25632
\code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
25634
25633
but it may also give rise to a demotion
25635
- (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
25636
- and it may have no effect on the type of $v$
25634
+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$
25635
+ and potentially promoting it to some other type of interest).
25636
+ It may also have no effect on the type of $v$
25637
25637
(e.g., when the static type of $e$ is not a type of interest).
25638
25638
These details will be specified in a future version of this specification.
25639
25639
@@ -25813,15 +25813,20 @@ \section*{Appendix: Algorithmic Subtyping}
25813
25813
the one which is specified in Fig.~\ref{fig:subtypeRules}.
25814
25814
It shows that Dart subtyping relationships can be decided
25815
25815
with good performance.
25816
+ This section is not normative.
25816
25817
25817
25818
\LMHash{}%
25818
25819
In this algorithm, types are considered to be the same when they have
25819
25820
the same canonical syntax
25820
25821
(\ref{theCanonicalSyntaxOfTypes}).
25822
+ \commentary{%
25823
+ For example, \SubtypeStd{\code{C}}{\code{C}} does not hold if
25824
+ the two occurrences of \code{C} refer to declarations in different libraries.%
25825
+ }
25821
25826
The algorithm must be performed such that the first case that matches
25822
25827
is always the case which is performed.
25823
25828
The algorithm produces results which are both positive and negative
25824
- (\commentary{
25829
+ (\commentary{%
25825
25830
that is, in some situations the subtype relation is determined to be false%
25826
25831
}),
25827
25832
which is important for performance because
@@ -25833,16 +25838,18 @@ \section*{Appendix: Algorithmic Subtyping}
25833
25838
\begin{itemize}
25834
25839
\item
25835
25840
\textbf{Reflexivity:}
25836
- if $T_0$ and $T_1$ are the same type then \SubtypeNE{T_0}{T_1}
25841
+ if $T_0$ and $T_1$ are the same atomic type then \SubtypeNE{T_0}{T_1}.
25837
25842
25838
25843
\commentary{%
25839
- Note that this check is necessary as the base case for primitive types,
25844
+ This check is necessary as the base case for primitive types,
25840
25845
and type variables, but not for composite types.
25841
25846
In particular, a structural equality check is admissible,
25842
25847
but not required here.
25843
- Pragmatically, non-constant time identity checks here are
25844
- counter-productive.
25845
- So this rule should only be used when $T$ is atomic.%
25848
+ Non-constant time identity checks here are counter-productive
25849
+ because the following rules will yield the same result anyway,
25850
+ so we may just perform a full traversal of a large structure twice
25851
+ for no reason.
25852
+ Hence, this rule is only used when the given type is atomic.%
25846
25853
}
25847
25854
\item
25848
25855
\textbf{Right Top:}
@@ -25852,7 +25859,7 @@ \section*{Appendix: Algorithmic Subtyping}
25852
25859
if $T_0$ is \DYNAMIC{} or \VOID{}
25853
25860
then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
25854
25861
\item
25855
- \textbf{Left Bottom:}
25862
+ \textbf{Bottom:}
25856
25863
if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
25857
25864
\item
25858
25865
\textbf{Right Object:}
@@ -25905,7 +25912,7 @@ \section*{Appendix: Algorithmic Subtyping}
25905
25912
or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
25906
25913
then \SubtypeNE{T_0}{T_1}.
25907
25914
25908
- \commentary{
25915
+ \commentary{%
25909
25916
Note that this rule is admissible, and can be safely elided if desired.%
25910
25917
}
25911
25918
\item
@@ -25988,7 +25995,7 @@ \section*{Appendix: Algorithmic Subtyping}
25988
25995
for $i \in 0 .. q$.
25989
25996
\item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
25990
25997
\item $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
25991
- have the same canonical syntax , for $i \in 0 .. k$.
25998
+ are subtypes of each other , for $i \in 0 .. k$.
25992
25999
\end{itemize}
25993
26000
\item
25994
26001
\textbf{Named Function Types:}
@@ -26029,8 +26036,7 @@ \section*{Appendix: Algorithmic Subtyping}
26029
26036
\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
26031
26038
$B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
26032
- have the same canonical syntax,
26033
- for each $i \in 0 .. k$.
26039
+ are subtypes of each other, for each $i \in 0 .. k$.
26034
26040
\end{itemize}
26035
26041
26036
26042
\commentary{%
0 commit comments