@@ -24753,15 +24753,6 @@ \subsection{Type Promotion}
24753
24753
then $T$ is also a type of interest.%
24754
24754
}
24755
24755
24756
- \LMHash{}%
24757
- The initial stack of types of interest for $v$ has exactly one element,
24758
- namely the declared type.
24759
- This is the stack of types of interest
24760
- for the declaring occurrence of the name of $v$
24761
- (\commentary{%
24762
- that is, the very first time the variable is mentioned, \ref{variables}%
24763
- }).
24764
-
24765
24756
\commentary{%
24766
24757
The flow analysis will be specified in
24767
24758
a future version of this specification.
@@ -24771,9 +24762,21 @@ \subsection{Type Promotion}
24771
24762
based on the same properties of locations
24772
24763
that are immediate predecessors of $\ell$
24773
24764
in the control flow graph,
24774
- ending in the declaration of $v$.%
24765
+ ending in the declaration of $v$.
24766
+ At this point we just specify the initial step,
24767
+ and the situations where promotion may occur.%
24775
24768
}
24776
24769
24770
+ \LMHash{}%
24771
+ The initial stack of types of interest for $v$ has exactly one element,
24772
+ namely the declared type
24773
+ (\ref{localVariableDeclaration}).
24774
+ This is the stack of types of interest
24775
+ for the declaring occurrence of the name of $v$
24776
+ (\commentary{%
24777
+ i.e., the very first time the variable is mentioned, \ref{variables}%
24778
+ }).
24779
+
24777
24780
\LMHash{}%
24778
24781
If a local variable $v$ has an initializing expression
24779
24782
and does not have the modifier \FINAL,
@@ -24813,20 +24816,91 @@ \subsection{Type Promotion}
24813
24816
Consider the situation
24814
24817
where the declaration of a local variable $v$ is of the form
24815
24818
\code{\LATE?\,\,\VAR\,\,$v$ = $e$;}
24816
- where the static type of $e$ is of the form \code{$X$\,\&\,$T$}
24819
+ where the static type of $e$ is of the form \code{$X$\,\&\,\, $T$}
24817
24820
where $X$ is a type variable.
24818
24821
In this situation, the declared type of $v$ is \code{X}
24819
24822
(\ref{localVariableDeclaration}),
24820
- but the type \code{$X$\,\&\,$T$} is added to the stack of types of interest,
24821
- and the type of $v$ is immediately promoted to \code{$X$\,\&\,$T$}.
24823
+ but the type \code{$X$\,\&\,\, $T$} is added to the stack of types of interest,
24824
+ and the type of $v$ is immediately promoted to \code{$X$\,\&\,\, $T$}.
24822
24825
24823
24826
\commentary{%
24824
- Note that \code{$X$\,\&\,$T$} is not otherwise automatically a
24827
+ Note that \code{$X$\,\&\,\, $T$} is not otherwise automatically a
24825
24828
type of interest just because $X$ is a type of interest.
24826
24829
In particular, if $w$ is declared as
24827
24830
\code{\LATE?\,\,$X$\,\,$w$ = $e$;}
24828
- where the static type of $e$ is \code{$X$\,\&\,$T$},
24829
- the type of $w$ is \emph{not} immediately promoted to \code{$X$\,\&\,$T$}.%
24831
+ where the static type of $e$ is \code{$X$\,\&\,\,$T$},
24832
+ the type of $w$ is \emph{not} promoted to \code{$X$\,\&\,\,$T$}.%
24833
+ }
24834
+
24835
+ \LMHash{}%
24836
+ We now mention the locations where promotion may occur
24837
+ independently of the control flow.
24838
+
24839
+ \commentary{%
24840
+ We might say that these promotions are ``atomic'',
24841
+ and all other promotions are derived from these,
24842
+ and from the control flow.%
24843
+ }
24844
+
24845
+ \LMHash{}%
24846
+ Let $\ell$ be a location,
24847
+ and let $v$ be a local variable which is in scope at $\ell$.
24848
+ Assume that $\ell$ occurs after the declaration of $v$.
24849
+ The expressions that give rise to promotion or demotion
24850
+ of the type of $v$ at $\ell$
24851
+ are the following:
24852
+
24853
+ \begin{itemize}
24854
+ \item A type test of the form \code{$v$\,\,\IS\,\,$T$}.
24855
+ \item A type check of the form \code{$v$\,\,\AS\,\,$T$}.
24856
+ \item An assignment of the form \code{$v$\,\,=\,\,$e$}
24857
+ where the static type of $e$ is a type of interest for $v$ at $\ell$,
24858
+ and similarly for compound assignments
24859
+ (\ref{compoundAssignment})
24860
+ including \lit{??=}.
24861
+ \item An equality test of the form \code{$v$\,\,==\,\,$e$} or
24862
+ \code{$e$\,\,==\,\,$v$}, where $e$ is \NULL,
24863
+ optionally wrapped in one or more parentheses,
24864
+ and similarly for \lit{!=}.
24865
+ \end{itemize}
24866
+
24867
+ \LMHash{}%
24868
+ In particular,
24869
+ a check of the form \code{$v$\,\,==\,\,\NULL},
24870
+ \code{\NULL\,\,==\,\,$v$},
24871
+ or \code{$v$\,\,\IS\,\,Null}
24872
+ where $v$ has type $T$ at $\ell$
24873
+ promotes the type of $v$
24874
+ to \code{Null} in the \TRUE{} continuation,
24875
+ and to \NonNullType{$T$} in the \FALSE{} continuation.
24876
+
24877
+ \LMHash{}%
24878
+ %% TODO(eernst), for review: The null safety spec says that `T?` is
24879
+ %% promoted to `T`, but implementations _do_ promote `X extends int?` to
24880
+ %% `X & int`. So I specify that.
24881
+ A check of the form \code{$v$\,\,!=\,\,\NULL},
24882
+ \code{\NULL\,\,!=\,\,$v$},
24883
+ or \code{$v$\,\,\IS\,\,$T$}
24884
+ where $v$ has type $T$ at $\ell$
24885
+ promotes the type of $v$
24886
+ to \NonNullType{$T$} in the \TRUE{} continuation,
24887
+ and to \code{Null} in the \FALSE{} continuation.
24888
+
24889
+ \commentary{%
24890
+ The resulting type of $v$ may be the obvious one, e.g.,
24891
+ \code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
24892
+ but it may also give rise to a demotion
24893
+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
24894
+ and it may have no effect on the type of $v$
24895
+ (e.g., when the static type of $e$ is not a type of interest).
24896
+ These details will be specified in a future version of this specification.
24897
+
24898
+ Every non-trivial type of control flow determines the control flow graph,
24899
+ and the control flow graph determines which of the above
24900
+ may or must have occurred at $\ell$,
24901
+ and hence gives rise to the stack of types of interest of $v$ at $\ell$,
24902
+ which in turn determines the type of $v$ at $\ell$.
24903
+ This part of the flow analysis will also be specified in the future.%
24830
24904
}
24831
24905
24832
24906
@@ -24988,32 +25062,11 @@ \section{Null safety} %% !!!TODO!!!
24988
25062
%% !!!At the end: Search Null, change to Never where appropriate
24989
25063
%% !!!Search all `TODO`.*null
24990
25064
24991
- \subsubsection{Null promotion}
24992
- \LMLabel{}
24993
-
24994
- !!!
24995
-
24996
- The machinery of type promotion is extended to promote the type of
24997
- variables based on nullability checks subject to the same set of
24998
- restrictions as normal promotion. The relevant checks and the types
24999
- they are considered to promote to are as follows.
25000
-
25001
- A check of the form \code{$e$ == null} or of the form
25002
- \code{$e$\,\,\IS\,\,Null} where $e$ has static type $T$ promotes the
25003
- type of $e$ to \code{Null} in the \code{true} continuation, and to
25004
- \NonNullType{$T$} in the \code{false} continuation.
25005
-
25006
- A check of the form \code{$e$ != null} or of the form
25007
- \code{$e$\,\,\IS\,\,$T$} where $e$ has static type
25008
- \code{$T$?}\ promotes the type of $e$ to $T$ in the \code{true}
25009
- continuation, and to \code{Null} in the \code{false} continuation.
25010
-
25011
- The static type of an expression \code{$e$!} is \NonNullType{$T$}
25012
- where $T$ is the static type of $e$.
25013
-
25014
25065
\subsubsection{Null aware operator}
25015
25066
\LMLabel{nullShorteningTransformation}
25016
25067
25068
+ !!!
25069
+
25017
25070
The semantics of the null aware operator \code{?.} are defined via a source to source
25018
25071
translation of expressions into Dart code extended with a let binding construct.
25019
25072
The translation is defined using meta-level functions over syntax. We use the
0 commit comments