@@ -23328,7 +23328,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23328
23328
\DefEquals{\UpperBoundType{$T_1$}{$T_2$}}{T_2},
23329
23329
if \SubtypeNE{T_1}{T_2}.
23330
23330
23331
- \commentary{
23331
+ \commentary{%
23332
23332
In this and in the following cases, both types must be interface types.%
23333
23333
}
23334
23334
\item
@@ -23585,7 +23585,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23585
23585
\DefEquals{\LowerBoundType{$T_1$}{$T_2$}}{\code{Never}}, otherwise.
23586
23586
\end{itemize}
23587
23587
23588
- \rationale{
23588
+ \rationale{%
23589
23589
The rules defining \UpperBoundTypeName{} and \LowerBoundTypeName{}
23590
23590
are somewhat redundant in that they explicitly specify
23591
23591
a lot of pairs of symmetric cases.
@@ -25377,6 +25377,7 @@ \subsection{Type Promotion}
25377
25377
}
25378
25378
25379
25379
\LMHash{}%
25380
+ \BlindDefineSymbol{\ell, v}%
25380
25381
Let $\ell$ be a location,
25381
25382
and let $v$ be a local variable which is in scope at $\ell$.
25382
25383
Assume that $\ell$ occurs after the declaration of $v$.
@@ -25400,34 +25401,33 @@ \subsection{Type Promotion}
25400
25401
25401
25402
\LMHash{}%
25402
25403
In particular,
25403
- a check of the form \code{$v$\,\,==\,\,\NULL},
25404
- \code{\NULL\,\,==\,\,$v$},
25405
- or \code{$v$\,\,\IS\,\,Null}
25404
+ an expression of the form \code{$v$\,\,==\,\,\NULL} or
25405
+ \code{\NULL\,\,==\,\,$v$}
25406
25406
where $v$ has type $T$ at $\ell$
25407
25407
promotes the type of $v$
25408
- to \code{Null} in the \TRUE{} continuation,
25409
- and to \NonNullType{$T$} in the \FALSE{} continuation.
25410
-
25411
- %% TODO(eernst), for review: The null safety spec says that `T?` is
25412
- %% promoted to `T`, but implementations _do_ promote `X extends int?` to
25413
- %% `X & int`. So we may be able to specify something which will yield
25414
- %% slightly more precise types, and which is more precisely the implemented
25415
- %% behavior.
25416
- \LMHash{}%
25417
- A check of the form \code{$v$\,\,!=\,\,\NULL},
25418
- \code{\NULL\,\,!=\,\,$v$},
25419
- or \code{$v$\,\,\IS\,\,$T$}
25420
- where $v$ has static type $T?$ at $\ell$
25408
+ to \NonNullType{$T$} in the \FALSE{} continuation;
25409
+ and an expression of the form \code{$v$\,\,!=\,\,\NULL} or
25410
+ \code{\NULL\,\,!=\,\,$v$}
25411
+ where $v$ has static type $T$ at $\ell$
25412
+ promotes the type of $v$
25413
+ to \NonNullType{$T$} in the \TRUE{} continuation.
25414
+
25415
+ \LMHash{}%
25416
+ Similarly, a type test of the form \code{$v$\,\,\IS\,\,$T$}
25421
25417
promotes the type of $v$
25422
25418
to $T$ in the \TRUE{} continuation,
25423
- and to \code{Null} in the \FALSE{} continuation.
25419
+ and a type check of the form \code{$v$\,\,\AS\,\,$T$}
25420
+ promotes the type of $v$
25421
+ to $T$ in the continuation where the expression evaluated to an object
25422
+ (\commentary{that is, it did not throw}).
25424
25423
25425
25424
\commentary{%
25426
25425
The resulting type of $v$ may be the obvious one, e.g.,
25427
25426
\code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
25428
25427
but it may also give rise to a demotion
25429
- (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
25430
- and it may have no effect on the type of $v$
25428
+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$
25429
+ and potentially promoting it to some other type of interest).
25430
+ It may also have no effect on the type of $v$
25431
25431
(e.g., when the static type of $e$ is not a type of interest).
25432
25432
These details will be specified in a future version of this specification.
25433
25433
@@ -25607,15 +25607,20 @@ \section*{Appendix: Algorithmic Subtyping}
25607
25607
the one which is specified in Fig.~\ref{fig:subtypeRules}.
25608
25608
It shows that Dart subtyping relationships can be decided
25609
25609
with good performance.
25610
+ This section is not normative.
25610
25611
25611
25612
\LMHash{}%
25612
25613
In this algorithm, types are considered to be the same when they have
25613
25614
the same canonical syntax
25614
25615
(\ref{theCanonicalSyntaxOfTypes}).
25616
+ \commentary{%
25617
+ For example, \SubtypeStd{\code{C}}{\code{C}} does not hold if
25618
+ the two occurrences of \code{C} refer to declarations in different libraries.%
25619
+ }
25615
25620
The algorithm must be performed such that the first case that matches
25616
25621
is always the case which is performed.
25617
25622
The algorithm produces results which are both positive and negative
25618
- (\commentary{
25623
+ (\commentary{%
25619
25624
that is, in some situations the subtype relation is determined to be false%
25620
25625
}),
25621
25626
which is important for performance because
@@ -25627,16 +25632,18 @@ \section*{Appendix: Algorithmic Subtyping}
25627
25632
\begin{itemize}
25628
25633
\item
25629
25634
\textbf{Reflexivity:}
25630
- if $T_0$ and $T_1$ are the same type then \SubtypeNE{T_0}{T_1}
25635
+ if $T_0$ and $T_1$ are the same atomic type then \SubtypeNE{T_0}{T_1}.
25631
25636
25632
25637
\commentary{%
25633
- Note that this check is necessary as the base case for primitive types,
25638
+ This check is necessary as the base case for primitive types,
25634
25639
and type variables, but not for composite types.
25635
25640
In particular, a structural equality check is admissible,
25636
25641
but not required here.
25637
- Pragmatically, non-constant time identity checks here are
25638
- counter-productive.
25639
- So this rule should only be used when $T$ is atomic.%
25642
+ Non-constant time identity checks here are counter-productive
25643
+ because the following rules will yield the same result anyway,
25644
+ so we may just perform a full traversal of a large structure twice
25645
+ for no reason.
25646
+ Hence, this rule is only used when the given type is atomic.%
25640
25647
}
25641
25648
\item
25642
25649
\textbf{Right Top:}
@@ -25646,7 +25653,7 @@ \section*{Appendix: Algorithmic Subtyping}
25646
25653
if $T_0$ is \DYNAMIC{} or \VOID{}
25647
25654
then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
25648
25655
\item
25649
- \textbf{Left Bottom:}
25656
+ \textbf{Bottom:}
25650
25657
if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
25651
25658
\item
25652
25659
\textbf{Right Object:}
@@ -25699,7 +25706,7 @@ \section*{Appendix: Algorithmic Subtyping}
25699
25706
or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
25700
25707
then \SubtypeNE{T_0}{T_1}.
25701
25708
25702
- \commentary{
25709
+ \commentary{%
25703
25710
Note that this rule is admissible, and can be safely elided if desired.%
25704
25711
}
25705
25712
\item
@@ -25782,7 +25789,7 @@ \section*{Appendix: Algorithmic Subtyping}
25782
25789
for $i \in 0 .. q$.
25783
25790
\item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
25784
25791
\item $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
25785
- have the same canonical syntax , for $i \in 0 .. k$.
25792
+ are subtypes of each other , for $i \in 0 .. k$.
25786
25793
\end{itemize}
25787
25794
\item
25788
25795
\textbf{Named Function Types:}
@@ -25823,8 +25830,7 @@ \section*{Appendix: Algorithmic Subtyping}
25823
25830
\SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
25824
25831
\item
25825
25832
$B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
25826
- have the same canonical syntax,
25827
- for each $i \in 0 .. k$.
25833
+ are subtypes of each other, for each $i \in 0 .. k$.
25828
25834
\end{itemize}
25829
25835
25830
25836
\commentary{%
0 commit comments