@@ -23600,7 +23600,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23600
23600
\DefEquals{\UpperBoundType{$T_1$}{$T_2$}}{T_2},
23601
23601
if \SubtypeNE{T_1}{T_2}.
23602
23602
23603
- \commentary{
23603
+ \commentary{%
23604
23604
In this and in the following cases, both types must be interface types.%
23605
23605
}
23606
23606
\item
@@ -23857,7 +23857,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23857
23857
\DefEquals{\LowerBoundType{$T_1$}{$T_2$}}{\code{Never}}, otherwise.
23858
23858
\end{itemize}
23859
23859
23860
- \rationale{
23860
+ \rationale{%
23861
23861
The rules defining \UpperBoundTypeName{} and \LowerBoundTypeName{}
23862
23862
are somewhat redundant in that they explicitly specify
23863
23863
a lot of pairs of symmetric cases.
@@ -25675,6 +25675,7 @@ \subsection{Type Promotion}
25675
25675
}
25676
25676
25677
25677
\LMHash{}%
25678
+ \BlindDefineSymbol{\ell, v}%
25678
25679
Let $\ell$ be a location,
25679
25680
and let $v$ be a local variable which is in scope at $\ell$.
25680
25681
Assume that $\ell$ occurs after the declaration of $v$.
@@ -25698,34 +25699,33 @@ \subsection{Type Promotion}
25698
25699
25699
25700
\LMHash{}%
25700
25701
In 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$}
25704
25704
where $v$ has type $T$ at $\ell$
25705
25705
promotes 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$}
25719
25715
promotes the type of $v$
25720
25716
to $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}).
25722
25721
25723
25722
\commentary{%
25724
25723
The resulting type of $v$ may be the obvious one, e.g.,
25725
25724
\code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
25726
25725
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$
25729
25729
(e.g., when the static type of $e$ is not a type of interest).
25730
25730
These details will be specified in a future version of this specification.
25731
25731
@@ -25880,15 +25880,20 @@ \section*{Appendix: Algorithmic Subtyping}
25880
25880
the one which is specified in Fig.~\ref{fig:subtypeRules}.
25881
25881
It shows that Dart subtyping relationships can be decided
25882
25882
with good performance.
25883
+ This section is not normative.
25883
25884
25884
25885
\LMHash{}%
25885
25886
In this algorithm, types are considered to be the same when they have
25886
25887
the same canonical syntax
25887
25888
(\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
+ }
25888
25893
The algorithm must be performed such that the first case that matches
25889
25894
is always the case which is performed.
25890
25895
The algorithm produces results which are both positive and negative
25891
- (\commentary{
25896
+ (\commentary{%
25892
25897
that is, in some situations the subtype relation is determined to be false%
25893
25898
}),
25894
25899
which is important for performance because
@@ -25900,16 +25905,18 @@ \section*{Appendix: Algorithmic Subtyping}
25900
25905
\begin{itemize}
25901
25906
\item
25902
25907
\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}.
25904
25909
25905
25910
\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,
25907
25912
and type variables, but not for composite types.
25908
25913
In particular, a structural equality check is admissible,
25909
25914
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.%
25913
25920
}
25914
25921
\item
25915
25922
\textbf{Right Top:}
@@ -25919,7 +25926,7 @@ \section*{Appendix: Algorithmic Subtyping}
25919
25926
if $T_0$ is \DYNAMIC{} or \VOID{}
25920
25927
then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
25921
25928
\item
25922
- \textbf{Left Bottom:}
25929
+ \textbf{Bottom:}
25923
25930
if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
25924
25931
\item
25925
25932
\textbf{Right Object:}
@@ -25972,7 +25979,7 @@ \section*{Appendix: Algorithmic Subtyping}
25972
25979
or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
25973
25980
then \SubtypeNE{T_0}{T_1}.
25974
25981
25975
- \commentary{
25982
+ \commentary{%
25976
25983
Note that this rule is admissible, and can be safely elided if desired.%
25977
25984
}
25978
25985
\item
@@ -26055,7 +26062,7 @@ \section*{Appendix: Algorithmic Subtyping}
26055
26062
for $i \in 0 .. q$.
26056
26063
\item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
26057
26064
\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$.
26059
26066
\end{itemize}
26060
26067
\item
26061
26068
\textbf{Named Function Types:}
@@ -26096,8 +26103,7 @@ \section*{Appendix: Algorithmic Subtyping}
26096
26103
\SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
26097
26104
\item
26098
26105
$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$.
26101
26107
\end{itemize}
26102
26108
26103
26109
\commentary{%
0 commit comments