@@ -13704,7 +13704,7 @@ \subsubsection{Ordinary Invocation}
13704
13704
Otherwise, let $d$ be the result of getter lookup
13705
13705
for $m$ in $T$ with respect to $L$,
13706
13706
and let $F$ be the return type of $d$.
13707
- (\commentary{
13707
+ (\commentary{%
13708
13708
Since \code{$T$.$m$} exists we cannot have a failure in both lookups.%
13709
13709
})
13710
13710
If the getter return type $F$ is an interface type
@@ -13728,7 +13728,7 @@ \subsubsection{Ordinary Invocation}
13728
13728
\LMHash{}%
13729
13729
It is a compile-time error to invoke an instance method on a type literal
13730
13730
that is immediately followed by the token `.' (a period).
13731
- \commentary{
13731
+ \commentary{%
13732
13732
For instance, \code{int.toString()} is an error.%
13733
13733
}
13734
13734
@@ -20316,13 +20316,13 @@ \subsection{Type Aliases}
20316
20316
it is a compile-time error if $T$ is not regular-bounded,
20317
20317
and it is a compile-time error if any type occurring in $T$ is not well-bounded.
20318
20318
20319
- \commentary{
20319
+ \commentary{%
20320
20320
This means that the bounds declared for
20321
20321
the formal type parameters of a generic type alias
20322
20322
must be such that when they are satisfied,
20323
20323
the bounds that pertain to the body are also satisfied,
20324
20324
and a type occurring as a subterm of the body can violate its bounds,
20325
- but only if it is a correct super-bounded type.
20325
+ but only if it is a correct super-bounded type.%
20326
20326
}
20327
20327
20328
20328
\LMHash{}%
@@ -22363,7 +22363,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
22363
22363
\DefEquals{\UpperBoundType{$T_1$}{$T_2$}}{T_2},
22364
22364
if \SubtypeNE{T_1}{T_2}.
22365
22365
22366
- \commentary{
22366
+ \commentary{%
22367
22367
In this and in the following cases, both types must be interface types.%
22368
22368
}
22369
22369
\item
@@ -22620,7 +22620,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
22620
22620
\DefEquals{\LowerBoundType{$T_1$}{$T_2$}}{\code{Never}}, otherwise.
22621
22621
\end{itemize}
22622
22622
22623
- \rationale{
22623
+ \rationale{%
22624
22624
The rules defining \UpperBoundTypeName{} and \LowerBoundTypeName{}
22625
22625
are somewhat redundant in that they explicitly specify
22626
22626
a lot of pairs of symmetric cases.
@@ -24412,6 +24412,7 @@ \subsection{Type Promotion}
24412
24412
}
24413
24413
24414
24414
\LMHash{}%
24415
+ \BlindDefineSymbol{\ell, v}%
24415
24416
Let $\ell$ be a location,
24416
24417
and let $v$ be a local variable which is in scope at $\ell$.
24417
24418
Assume that $\ell$ occurs after the declaration of $v$.
@@ -24435,34 +24436,33 @@ \subsection{Type Promotion}
24435
24436
24436
24437
\LMHash{}%
24437
24438
In particular,
24438
- a check of the form \code{$v$\,\,==\,\,\NULL},
24439
- \code{\NULL\,\,==\,\,$v$},
24440
- or \code{$v$\,\,\IS\,\,Null}
24439
+ an expression of the form \code{$v$\,\,==\,\,\NULL} or
24440
+ \code{\NULL\,\,==\,\,$v$}
24441
24441
where $v$ has type $T$ at $\ell$
24442
24442
promotes the type of $v$
24443
- to \code{Null} in the \TRUE{} continuation,
24444
- and to \NonNullType{$T$} in the \FALSE{} continuation.
24445
-
24446
- %% TODO(eernst), for review: The null safety spec says that `T?` is
24447
- %% promoted to `T`, but implementations _do_ promote `X extends int?` to
24448
- %% `X & int`. So we may be able to specify something which will yield
24449
- %% slightly more precise types, and which is more precisely the implemented
24450
- %% behavior.
24451
- \LMHash{}%
24452
- A check of the form \code{$v$\,\,!=\,\,\NULL},
24453
- \code{\NULL\,\,!=\,\,$v$},
24454
- or \code{$v$\,\,\IS\,\,$T$}
24455
- where $v$ has static type $T?$ at $\ell$
24443
+ to \NonNullType{$T$} in the \FALSE{} continuation;
24444
+ and an expression of the form \code{$v$\,\,!=\,\,\NULL} or
24445
+ \code{\NULL\,\,!=\,\,$v$}
24446
+ where $v$ has static type $T$ at $\ell$
24447
+ promotes the type of $v$
24448
+ to \NonNullType{$T$} in the \TRUE{} continuation.
24449
+
24450
+ \LMHash{}%
24451
+ Similarly, a type test of the form \code{$v$\,\,\IS\,\,$T$}
24456
24452
promotes the type of $v$
24457
24453
to $T$ in the \TRUE{} continuation,
24458
- and to \code{Null} in the \FALSE{} continuation.
24454
+ and a type check of the form \code{$v$\,\,\AS\,\,$T$}
24455
+ promotes the type of $v$
24456
+ to $T$ in the continuation where the expression evaluated to an object
24457
+ (\commentary{that is, it did not throw}).
24459
24458
24460
24459
\commentary{%
24461
24460
The resulting type of $v$ may be the obvious one, e.g.,
24462
24461
\code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
24463
24462
but it may also give rise to a demotion
24464
- (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
24465
- and it may have no effect on the type of $v$
24463
+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$
24464
+ and potentially promoting it to some other type of interest).
24465
+ It may also have no effect on the type of $v$
24466
24466
(e.g., when the static type of $e$ is not a type of interest).
24467
24467
These details will be specified in a future version of this specification.
24468
24468
@@ -24624,15 +24624,20 @@ \section*{Appendix: Algorithmic Subtyping}
24624
24624
the one which is specified in Fig.~\ref{fig:subtypeRules}.
24625
24625
It shows that Dart subtyping relationships can be decided
24626
24626
with good performance.
24627
+ This section is not normative.
24627
24628
24628
24629
\LMHash{}%
24629
24630
In this algorithm, types are considered to be the same when they have
24630
24631
the same canonical syntax
24631
24632
(\ref{theCanonicalSyntaxOfTypes}).
24633
+ \commentary{%
24634
+ For example, \SubtypeStd{\code{C}}{\code{C}} does not hold if
24635
+ the two occurrences of \code{C} refer to declarations in different libraries.%
24636
+ }
24632
24637
The algorithm must be performed such that the first case that matches
24633
24638
is always the case which is performed.
24634
24639
The algorithm produces results which are both positive and negative
24635
- (\commentary{
24640
+ (\commentary{%
24636
24641
that is, in some situations the subtype relation is determined to be false%
24637
24642
}),
24638
24643
which is important for performance because
@@ -24644,16 +24649,18 @@ \section*{Appendix: Algorithmic Subtyping}
24644
24649
\begin{itemize}
24645
24650
\item
24646
24651
\textbf{Reflexivity:}
24647
- if $T_0$ and $T_1$ are the same type then \SubtypeNE{T_0}{T_1}
24652
+ if $T_0$ and $T_1$ are the same atomic type then \SubtypeNE{T_0}{T_1}.
24648
24653
24649
24654
\commentary{%
24650
- Note that this check is necessary as the base case for primitive types,
24655
+ This check is necessary as the base case for primitive types,
24651
24656
and type variables, but not for composite types.
24652
24657
In particular, a structural equality check is admissible,
24653
24658
but not required here.
24654
- Pragmatically, non-constant time identity checks here are
24655
- counter-productive.
24656
- So this rule should only be used when $T$ is atomic.%
24659
+ Non-constant time identity checks here are counter-productive
24660
+ because the following rules will yield the same result anyway,
24661
+ so we may just perform a full traversal of a large structure twice
24662
+ for no reason.
24663
+ Hence, this rule is only used when the given type is atomic.%
24657
24664
}
24658
24665
\item
24659
24666
\textbf{Right Top:}
@@ -24663,7 +24670,7 @@ \section*{Appendix: Algorithmic Subtyping}
24663
24670
if $T_0$ is \DYNAMIC{} or \VOID{}
24664
24671
then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
24665
24672
\item
24666
- \textbf{Left Bottom:}
24673
+ \textbf{Bottom:}
24667
24674
if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
24668
24675
\item
24669
24676
\textbf{Right Object:}
@@ -24716,7 +24723,7 @@ \section*{Appendix: Algorithmic Subtyping}
24716
24723
or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
24717
24724
then \SubtypeNE{T_0}{T_1}.
24718
24725
24719
- \commentary{
24726
+ \commentary{%
24720
24727
Note that this rule is admissible, and can be safely elided if desired.%
24721
24728
}
24722
24729
\item
@@ -24799,7 +24806,7 @@ \section*{Appendix: Algorithmic Subtyping}
24799
24806
for $i \in 0 .. q$.
24800
24807
\item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
24801
24808
\item $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
24802
- have the same canonical syntax , for $i \in 0 .. k$.
24809
+ are subtypes of each other , for $i \in 0 .. k$.
24803
24810
\end{itemize}
24804
24811
\item
24805
24812
\textbf{Named Function Types:}
@@ -24840,8 +24847,7 @@ \section*{Appendix: Algorithmic Subtyping}
24840
24847
\SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
24841
24848
\item
24842
24849
$B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
24843
- have the same canonical syntax,
24844
- for each $i \in 0 .. k$.
24850
+ are subtypes of each other, for each $i \in 0 .. k$.
24845
24851
\end{itemize}
24846
24852
24847
24853
\commentary{%
0 commit comments