@@ -23607,7 +23607,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23607
23607
\DefEquals{\UpperBoundType{$T_1$}{$T_2$}}{T_2},
23608
23608
if \SubtypeNE{T_1}{T_2}.
23609
23609
23610
- \commentary{
23610
+ \commentary{%
23611
23611
In this and in the following cases, both types must be interface types.%
23612
23612
}
23613
23613
\item
@@ -23864,7 +23864,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23864
23864
\DefEquals{\LowerBoundType{$T_1$}{$T_2$}}{\code{Never}}, otherwise.
23865
23865
\end{itemize}
23866
23866
23867
- \rationale{
23867
+ \rationale{%
23868
23868
The rules defining \UpperBoundTypeName{} and \LowerBoundTypeName{}
23869
23869
are somewhat redundant in that they explicitly specify
23870
23870
a lot of pairs of symmetric cases.
@@ -25682,6 +25682,7 @@ \subsection{Type Promotion}
25682
25682
}
25683
25683
25684
25684
\LMHash{}%
25685
+ \BlindDefineSymbol{\ell, v}%
25685
25686
Let $\ell$ be a location,
25686
25687
and let $v$ be a local variable which is in scope at $\ell$.
25687
25688
Assume that $\ell$ occurs after the declaration of $v$.
@@ -25705,34 +25706,33 @@ \subsection{Type Promotion}
25705
25706
25706
25707
\LMHash{}%
25707
25708
In particular,
25708
- a check of the form \code{$v$\,\,==\,\,\NULL},
25709
- \code{\NULL\,\,==\,\,$v$},
25710
- or \code{$v$\,\,\IS\,\,Null}
25709
+ an expression of the form \code{$v$\,\,==\,\,\NULL} or
25710
+ \code{\NULL\,\,==\,\,$v$}
25711
25711
where $v$ has type $T$ at $\ell$
25712
25712
promotes the type of $v$
25713
- to \code{Null} in the \TRUE{} continuation,
25714
- and to \NonNullType{$T$} in the \FALSE{} continuation.
25715
-
25716
- %% TODO(eernst), for review: The null safety spec says that `T?` is
25717
- %% promoted to `T`, but implementations _do_ promote `X extends int?` to
25718
- %% `X & int`. So we may be able to specify something which will yield
25719
- %% slightly more precise types, and which is more precisely the implemented
25720
- %% behavior.
25721
- \LMHash{}%
25722
- A check of the form \code{$v$\,\,!=\,\,\NULL},
25723
- \code{\NULL\,\,!=\,\,$v$},
25724
- or \code{$v$\,\,\IS\,\,$T$}
25725
- where $v$ has static type $T?$ at $\ell$
25713
+ to \NonNullType{$T$} in the \FALSE{} continuation;
25714
+ and an expression of the form \code{$v$\,\,!=\,\,\NULL} or
25715
+ \code{\NULL\,\,!=\,\,$v$}
25716
+ where $v$ has static type $T$ at $\ell$
25717
+ promotes the type of $v$
25718
+ to \NonNullType{$T$} in the \TRUE{} continuation.
25719
+
25720
+ \LMHash{}%
25721
+ Similarly, a type test of the form \code{$v$\,\,\IS\,\,$T$}
25726
25722
promotes the type of $v$
25727
25723
to $T$ in the \TRUE{} continuation,
25728
- and to \code{Null} in the \FALSE{} continuation.
25724
+ and a type check of the form \code{$v$\,\,\AS\,\,$T$}
25725
+ promotes the type of $v$
25726
+ to $T$ in the continuation where the expression evaluated to an object
25727
+ (\commentary{that is, it did not throw}).
25729
25728
25730
25729
\commentary{%
25731
25730
The resulting type of $v$ may be the obvious one, e.g.,
25732
25731
\code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
25733
25732
but it may also give rise to a demotion
25734
- (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
25735
- and it may have no effect on the type of $v$
25733
+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$
25734
+ and potentially promoting it to some other type of interest).
25735
+ It may also have no effect on the type of $v$
25736
25736
(e.g., when the static type of $e$ is not a type of interest).
25737
25737
These details will be specified in a future version of this specification.
25738
25738
@@ -25887,15 +25887,20 @@ \section*{Appendix: Algorithmic Subtyping}
25887
25887
the one which is specified in Fig.~\ref{fig:subtypeRules}.
25888
25888
It shows that Dart subtyping relationships can be decided
25889
25889
with good performance.
25890
+ This section is not normative.
25890
25891
25891
25892
\LMHash{}%
25892
25893
In this algorithm, types are considered to be the same when they have
25893
25894
the same canonical syntax
25894
25895
(\ref{theCanonicalSyntaxOfTypes}).
25896
+ \commentary{%
25897
+ For example, \SubtypeStd{\code{C}}{\code{C}} does not hold if
25898
+ the two occurrences of \code{C} refer to declarations in different libraries.%
25899
+ }
25895
25900
The algorithm must be performed such that the first case that matches
25896
25901
is always the case which is performed.
25897
25902
The algorithm produces results which are both positive and negative
25898
- (\commentary{
25903
+ (\commentary{%
25899
25904
that is, in some situations the subtype relation is determined to be false%
25900
25905
}),
25901
25906
which is important for performance because
@@ -25907,16 +25912,18 @@ \section*{Appendix: Algorithmic Subtyping}
25907
25912
\begin{itemize}
25908
25913
\item
25909
25914
\textbf{Reflexivity:}
25910
- if $T_0$ and $T_1$ are the same type then \SubtypeNE{T_0}{T_1}
25915
+ if $T_0$ and $T_1$ are the same atomic type then \SubtypeNE{T_0}{T_1}.
25911
25916
25912
25917
\commentary{%
25913
- Note that this check is necessary as the base case for primitive types,
25918
+ This check is necessary as the base case for primitive types,
25914
25919
and type variables, but not for composite types.
25915
25920
In particular, a structural equality check is admissible,
25916
25921
but not required here.
25917
- Pragmatically, non-constant time identity checks here are
25918
- counter-productive.
25919
- So this rule should only be used when $T$ is atomic.%
25922
+ Non-constant time identity checks here are counter-productive
25923
+ because the following rules will yield the same result anyway,
25924
+ so we may just perform a full traversal of a large structure twice
25925
+ for no reason.
25926
+ Hence, this rule is only used when the given type is atomic.%
25920
25927
}
25921
25928
\item
25922
25929
\textbf{Right Top:}
@@ -25926,7 +25933,7 @@ \section*{Appendix: Algorithmic Subtyping}
25926
25933
if $T_0$ is \DYNAMIC{} or \VOID{}
25927
25934
then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
25928
25935
\item
25929
- \textbf{Left Bottom:}
25936
+ \textbf{Bottom:}
25930
25937
if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
25931
25938
\item
25932
25939
\textbf{Right Object:}
@@ -25979,7 +25986,7 @@ \section*{Appendix: Algorithmic Subtyping}
25979
25986
or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
25980
25987
then \SubtypeNE{T_0}{T_1}.
25981
25988
25982
- \commentary{
25989
+ \commentary{%
25983
25990
Note that this rule is admissible, and can be safely elided if desired.%
25984
25991
}
25985
25992
\item
@@ -26062,7 +26069,7 @@ \section*{Appendix: Algorithmic Subtyping}
26062
26069
for $i \in 0 .. q$.
26063
26070
\item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
26064
26071
\item $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
26065
- have the same canonical syntax , for $i \in 0 .. k$.
26072
+ are subtypes of each other , for $i \in 0 .. k$.
26066
26073
\end{itemize}
26067
26074
\item
26068
26075
\textbf{Named Function Types:}
@@ -26103,8 +26110,7 @@ \section*{Appendix: Algorithmic Subtyping}
26103
26110
\SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
26104
26111
\item
26105
26112
$B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
26106
- have the same canonical syntax,
26107
- for each $i \in 0 .. k$.
26113
+ are subtypes of each other, for each $i \in 0 .. k$.
26108
26114
\end{itemize}
26109
26115
26110
26116
\commentary{%
0 commit comments