@@ -24570,15 +24570,6 @@ \subsection{Type Promotion}
24570
24570
then $T$ is also a type of interest.%
24571
24571
}
24572
24572
24573
- \LMHash{}%
24574
- The initial stack of types of interest for $v$ has exactly one element,
24575
- namely the declared type.
24576
- This is the stack of types of interest
24577
- for the declaring occurrence of the name of $v$
24578
- (\commentary{%
24579
- that is, the very first time the variable is mentioned, \ref{variables}%
24580
- }).
24581
-
24582
24573
\commentary{%
24583
24574
The flow analysis will be specified in
24584
24575
a future version of this specification.
@@ -24588,9 +24579,21 @@ \subsection{Type Promotion}
24588
24579
based on the same properties of locations
24589
24580
that are immediate predecessors of $\ell$
24590
24581
in the control flow graph,
24591
- ending in the declaration of $v$.%
24582
+ ending in the declaration of $v$.
24583
+ At this point we just specify the initial step,
24584
+ and the situations where promotion may occur.%
24592
24585
}
24593
24586
24587
+ \LMHash{}%
24588
+ The initial stack of types of interest for $v$ has exactly one element,
24589
+ namely the declared type
24590
+ (\ref{localVariableDeclaration}).
24591
+ This is the stack of types of interest
24592
+ for the declaring occurrence of the name of $v$
24593
+ (\commentary{%
24594
+ i.e., the very first time the variable is mentioned, \ref{variables}%
24595
+ }).
24596
+
24594
24597
\LMHash{}%
24595
24598
If a local variable $v$ has an initializing expression
24596
24599
and does not have the modifier \FINAL,
@@ -24630,20 +24633,91 @@ \subsection{Type Promotion}
24630
24633
Consider the situation
24631
24634
where the declaration of a local variable $v$ is of the form
24632
24635
\code{\LATE?\,\,\VAR\,\,$v$ = $e$;}
24633
- where the static type of $e$ is of the form \code{$X$\,\&\,$T$}
24636
+ where the static type of $e$ is of the form \code{$X$\,\&\,\, $T$}
24634
24637
where $X$ is a type variable.
24635
24638
In this situation, the declared type of $v$ is \code{X}
24636
24639
(\ref{localVariableDeclaration}),
24637
- but the type \code{$X$\,\&\,$T$} is added to the stack of types of interest,
24638
- and the type of $v$ is immediately promoted to \code{$X$\,\&\,$T$}.
24640
+ but the type \code{$X$\,\&\,\, $T$} is added to the stack of types of interest,
24641
+ and the type of $v$ is immediately promoted to \code{$X$\,\&\,\, $T$}.
24639
24642
24640
24643
\commentary{%
24641
- Note that \code{$X$\,\&\,$T$} is not otherwise automatically a
24644
+ Note that \code{$X$\,\&\,\, $T$} is not otherwise automatically a
24642
24645
type of interest just because $X$ is a type of interest.
24643
24646
In particular, if $w$ is declared as
24644
24647
\code{\LATE?\,\,$X$\,\,$w$ = $e$;}
24645
- where the static type of $e$ is \code{$X$\,\&\,$T$},
24646
- the type of $w$ is \emph{not} immediately promoted to \code{$X$\,\&\,$T$}.%
24648
+ where the static type of $e$ is \code{$X$\,\&\,\,$T$},
24649
+ the type of $w$ is \emph{not} promoted to \code{$X$\,\&\,\,$T$}.%
24650
+ }
24651
+
24652
+ \LMHash{}%
24653
+ We now mention the locations where promotion may occur
24654
+ independently of the control flow.
24655
+
24656
+ \commentary{%
24657
+ We might say that these promotions are ``atomic'',
24658
+ and all other promotions are derived from these,
24659
+ and from the control flow.%
24660
+ }
24661
+
24662
+ \LMHash{}%
24663
+ Let $\ell$ be a location,
24664
+ and let $v$ be a local variable which is in scope at $\ell$.
24665
+ Assume that $\ell$ occurs after the declaration of $v$.
24666
+ The expressions that give rise to promotion or demotion
24667
+ of the type of $v$ at $\ell$
24668
+ are the following:
24669
+
24670
+ \begin{itemize}
24671
+ \item A type test of the form \code{$v$\,\,\IS\,\,$T$}.
24672
+ \item A type check of the form \code{$v$\,\,\AS\,\,$T$}.
24673
+ \item An assignment of the form \code{$v$\,\,=\,\,$e$}
24674
+ where the static type of $e$ is a type of interest for $v$ at $\ell$,
24675
+ and similarly for compound assignments
24676
+ (\ref{compoundAssignment})
24677
+ including \lit{??=}.
24678
+ \item An equality test of the form \code{$v$\,\,==\,\,$e$} or
24679
+ \code{$e$\,\,==\,\,$v$}, where $e$ is \NULL,
24680
+ optionally wrapped in one or more parentheses,
24681
+ and similarly for \lit{!=}.
24682
+ \end{itemize}
24683
+
24684
+ \LMHash{}%
24685
+ In particular,
24686
+ a check of the form \code{$v$\,\,==\,\,\NULL},
24687
+ \code{\NULL\,\,==\,\,$v$},
24688
+ or \code{$v$\,\,\IS\,\,Null}
24689
+ where $v$ has type $T$ at $\ell$
24690
+ promotes the type of $v$
24691
+ to \code{Null} in the \TRUE{} continuation,
24692
+ and to \NonNullType{$T$} in the \FALSE{} continuation.
24693
+
24694
+ \LMHash{}%
24695
+ %% TODO(eernst), for review: The null safety spec says that `T?` is
24696
+ %% promoted to `T`, but implementations _do_ promote `X extends int?` to
24697
+ %% `X & int`. So I specify that.
24698
+ A check of the form \code{$v$\,\,!=\,\,\NULL},
24699
+ \code{\NULL\,\,!=\,\,$v$},
24700
+ or \code{$v$\,\,\IS\,\,$T$}
24701
+ where $v$ has type $T$ at $\ell$
24702
+ promotes the type of $v$
24703
+ to \NonNullType{$T$} in the \TRUE{} continuation,
24704
+ and to \code{Null} in the \FALSE{} continuation.
24705
+
24706
+ \commentary{%
24707
+ The resulting type of $v$ may be the obvious one, e.g.,
24708
+ \code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
24709
+ but it may also give rise to a demotion
24710
+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
24711
+ and it may have no effect on the type of $v$
24712
+ (e.g., when the static type of $e$ is not a type of interest).
24713
+ These details will be specified in a future version of this specification.
24714
+
24715
+ Every non-trivial type of control flow determines the control flow graph,
24716
+ and the control flow graph determines which of the above
24717
+ may or must have occurred at $\ell$,
24718
+ and hence gives rise to the stack of types of interest of $v$ at $\ell$,
24719
+ which in turn determines the type of $v$ at $\ell$.
24720
+ This part of the flow analysis will also be specified in the future.%
24647
24721
}
24648
24722
24649
24723
@@ -24805,32 +24879,11 @@ \section{Null safety} %% !!!TODO!!!
24805
24879
%% !!!At the end: Search Null, change to Never where appropriate
24806
24880
%% !!!Search all `TODO`.*null
24807
24881
24808
- \subsubsection{Null promotion}
24809
- \LMLabel{}
24810
-
24811
- !!!
24812
-
24813
- The machinery of type promotion is extended to promote the type of
24814
- variables based on nullability checks subject to the same set of
24815
- restrictions as normal promotion. The relevant checks and the types
24816
- they are considered to promote to are as follows.
24817
-
24818
- A check of the form \code{$e$ == null} or of the form
24819
- \code{$e$\,\,\IS\,\,Null} where $e$ has static type $T$ promotes the
24820
- type of $e$ to \code{Null} in the \code{true} continuation, and to
24821
- \NonNullType{$T$} in the \code{false} continuation.
24822
-
24823
- A check of the form \code{$e$ != null} or of the form
24824
- \code{$e$\,\,\IS\,\,$T$} where $e$ has static type
24825
- \code{$T$?}\ promotes the type of $e$ to $T$ in the \code{true}
24826
- continuation, and to \code{Null} in the \code{false} continuation.
24827
-
24828
- The static type of an expression \code{$e$!} is \NonNullType{$T$}
24829
- where $T$ is the static type of $e$.
24830
-
24831
24882
\subsubsection{Null aware operator}
24832
24883
\LMLabel{nullShorteningTransformation}
24833
24884
24885
+ !!!
24886
+
24834
24887
The semantics of the null aware operator \code{?.} are defined via a source to source
24835
24888
translation of expressions into Dart code extended with a let binding construct.
24836
24889
The translation is defined using meta-level functions over syntax. We use the
0 commit comments