@@ -24732,15 +24732,6 @@ \subsection{Type Promotion}
24732
24732
then $T$ is also a type of interest.%
24733
24733
}
24734
24734
24735
- \LMHash{}%
24736
- The initial stack of types of interest for $v$ has exactly one element,
24737
- namely the declared type.
24738
- This is the stack of types of interest
24739
- for the declaring occurrence of the name of $v$
24740
- (\commentary{%
24741
- that is, the very first time the variable is mentioned, \ref{variables}%
24742
- }).
24743
-
24744
24735
\commentary{%
24745
24736
The flow analysis will be specified in
24746
24737
a future version of this specification.
@@ -24750,9 +24741,21 @@ \subsection{Type Promotion}
24750
24741
based on the same properties of locations
24751
24742
that are immediate predecessors of $\ell$
24752
24743
in the control flow graph,
24753
- ending in the declaration of $v$.%
24744
+ ending in the declaration of $v$.
24745
+ At this point we just specify the initial step,
24746
+ and the situations where promotion may occur.%
24754
24747
}
24755
24748
24749
+ \LMHash{}%
24750
+ The initial stack of types of interest for $v$ has exactly one element,
24751
+ namely the declared type
24752
+ (\ref{localVariableDeclaration}).
24753
+ This is the stack of types of interest
24754
+ for the declaring occurrence of the name of $v$
24755
+ (\commentary{%
24756
+ i.e., the very first time the variable is mentioned, \ref{variables}%
24757
+ }).
24758
+
24756
24759
\LMHash{}%
24757
24760
If a local variable $v$ has an initializing expression
24758
24761
and does not have the modifier \FINAL,
@@ -24792,20 +24795,91 @@ \subsection{Type Promotion}
24792
24795
Consider the situation
24793
24796
where the declaration of a local variable $v$ is of the form
24794
24797
\code{\LATE?\,\,\VAR\,\,$v$ = $e$;}
24795
- where the static type of $e$ is of the form \code{$X$\,\&\,$T$}
24798
+ where the static type of $e$ is of the form \code{$X$\,\&\,\, $T$}
24796
24799
where $X$ is a type variable.
24797
24800
In this situation, the declared type of $v$ is \code{X}
24798
24801
(\ref{localVariableDeclaration}),
24799
- but the type \code{$X$\,\&\,$T$} is added to the stack of types of interest,
24800
- and the type of $v$ is immediately promoted to \code{$X$\,\&\,$T$}.
24802
+ but the type \code{$X$\,\&\,\, $T$} is added to the stack of types of interest,
24803
+ and the type of $v$ is immediately promoted to \code{$X$\,\&\,\, $T$}.
24801
24804
24802
24805
\commentary{%
24803
- Note that \code{$X$\,\&\,$T$} is not otherwise automatically a
24806
+ Note that \code{$X$\,\&\,\, $T$} is not otherwise automatically a
24804
24807
type of interest just because $X$ is a type of interest.
24805
24808
In particular, if $w$ is declared as
24806
24809
\code{\LATE?\,\,$X$\,\,$w$ = $e$;}
24807
- where the static type of $e$ is \code{$X$\,\&\,$T$},
24808
- the type of $w$ is \emph{not} immediately promoted to \code{$X$\,\&\,$T$}.%
24810
+ where the static type of $e$ is \code{$X$\,\&\,\,$T$},
24811
+ the type of $w$ is \emph{not} promoted to \code{$X$\,\&\,\,$T$}.%
24812
+ }
24813
+
24814
+ \LMHash{}%
24815
+ We now mention the locations where promotion may occur
24816
+ independently of the control flow.
24817
+
24818
+ \commentary{%
24819
+ We might say that these promotions are ``atomic'',
24820
+ and all other promotions are derived from these,
24821
+ and from the control flow.%
24822
+ }
24823
+
24824
+ \LMHash{}%
24825
+ Let $\ell$ be a location,
24826
+ and let $v$ be a local variable which is in scope at $\ell$.
24827
+ Assume that $\ell$ occurs after the declaration of $v$.
24828
+ The expressions that give rise to promotion or demotion
24829
+ of the type of $v$ at $\ell$
24830
+ are the following:
24831
+
24832
+ \begin{itemize}
24833
+ \item A type test of the form \code{$v$\,\,\IS\,\,$T$}.
24834
+ \item A type check of the form \code{$v$\,\,\AS\,\,$T$}.
24835
+ \item An assignment of the form \code{$v$\,\,=\,\,$e$}
24836
+ where the static type of $e$ is a type of interest for $v$ at $\ell$,
24837
+ and similarly for compound assignments
24838
+ (\ref{compoundAssignment})
24839
+ including \lit{??=}.
24840
+ \item An equality test of the form \code{$v$\,\,==\,\,$e$} or
24841
+ \code{$e$\,\,==\,\,$v$}, where $e$ is \NULL,
24842
+ optionally wrapped in one or more parentheses,
24843
+ and similarly for \lit{!=}.
24844
+ \end{itemize}
24845
+
24846
+ \LMHash{}%
24847
+ In particular,
24848
+ a check of the form \code{$v$\,\,==\,\,\NULL},
24849
+ \code{\NULL\,\,==\,\,$v$},
24850
+ or \code{$v$\,\,\IS\,\,Null}
24851
+ where $v$ has type $T$ at $\ell$
24852
+ promotes the type of $v$
24853
+ to \code{Null} in the \TRUE{} continuation,
24854
+ and to \NonNullType{$T$} in the \FALSE{} continuation.
24855
+
24856
+ \LMHash{}%
24857
+ %% TODO(eernst), for review: The null safety spec says that `T?` is
24858
+ %% promoted to `T`, but implementations _do_ promote `X extends int?` to
24859
+ %% `X & int`. So I specify that.
24860
+ A check of the form \code{$v$\,\,!=\,\,\NULL},
24861
+ \code{\NULL\,\,!=\,\,$v$},
24862
+ or \code{$v$\,\,\IS\,\,$T$}
24863
+ where $v$ has type $T$ at $\ell$
24864
+ promotes the type of $v$
24865
+ to \NonNullType{$T$} in the \TRUE{} continuation,
24866
+ and to \code{Null} in the \FALSE{} continuation.
24867
+
24868
+ \commentary{%
24869
+ The resulting type of $v$ may be the obvious one, e.g.,
24870
+ \code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
24871
+ but it may also give rise to a demotion
24872
+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
24873
+ and it may have no effect on the type of $v$
24874
+ (e.g., when the static type of $e$ is not a type of interest).
24875
+ These details will be specified in a future version of this specification.
24876
+
24877
+ Every non-trivial type of control flow determines the control flow graph,
24878
+ and the control flow graph determines which of the above
24879
+ may or must have occurred at $\ell$,
24880
+ and hence gives rise to the stack of types of interest of $v$ at $\ell$,
24881
+ which in turn determines the type of $v$ at $\ell$.
24882
+ This part of the flow analysis will also be specified in the future.%
24809
24883
}
24810
24884
24811
24885
@@ -24967,32 +25041,11 @@ \section{Null safety} %% !!!TODO!!!
24967
25041
%% !!!At the end: Search Null, change to Never where appropriate
24968
25042
%% !!!Search all `TODO`.*null
24969
25043
24970
- \subsubsection{Null promotion}
24971
- \LMLabel{}
24972
-
24973
- !!!
24974
-
24975
- The machinery of type promotion is extended to promote the type of
24976
- variables based on nullability checks subject to the same set of
24977
- restrictions as normal promotion. The relevant checks and the types
24978
- they are considered to promote to are as follows.
24979
-
24980
- A check of the form \code{$e$ == null} or of the form
24981
- \code{$e$\,\,\IS\,\,Null} where $e$ has static type $T$ promotes the
24982
- type of $e$ to \code{Null} in the \code{true} continuation, and to
24983
- \NonNullType{$T$} in the \code{false} continuation.
24984
-
24985
- A check of the form \code{$e$ != null} or of the form
24986
- \code{$e$\,\,\IS\,\,$T$} where $e$ has static type
24987
- \code{$T$?}\ promotes the type of $e$ to $T$ in the \code{true}
24988
- continuation, and to \code{Null} in the \code{false} continuation.
24989
-
24990
- The static type of an expression \code{$e$!} is \NonNullType{$T$}
24991
- where $T$ is the static type of $e$.
24992
-
24993
25044
\subsubsection{Null aware operator}
24994
25045
\LMLabel{nullShorteningTransformation}
24995
25046
25047
+ !!!
25048
+
24996
25049
The semantics of the null aware operator \code{?.} are defined via a source to source
24997
25050
translation of expressions into Dart code extended with a let binding construct.
24998
25051
The translation is defined using meta-level functions over syntax. We use the
0 commit comments