@@ -24303,15 +24303,6 @@ \subsection{Type Promotion}
24303
24303
then $T$ is also a type of interest.%
24304
24304
}
24305
24305
24306
- \LMHash{}%
24307
- The initial stack of types of interest for $v$ has exactly one element,
24308
- namely the declared type.
24309
- This is the stack of types of interest
24310
- for the declaring occurrence of the name of $v$
24311
- (\commentary{%
24312
- that is, the very first time the variable is mentioned, \ref{variables}%
24313
- }).
24314
-
24315
24306
\commentary{%
24316
24307
The flow analysis will be specified in
24317
24308
a future version of this specification.
@@ -24321,9 +24312,21 @@ \subsection{Type Promotion}
24321
24312
based on the same properties of locations
24322
24313
that are immediate predecessors of $\ell$
24323
24314
in the control flow graph,
24324
- ending in the declaration of $v$.%
24315
+ ending in the declaration of $v$.
24316
+ At this point we just specify the initial step,
24317
+ and the situations where promotion may occur.%
24325
24318
}
24326
24319
24320
+ \LMHash{}%
24321
+ The initial stack of types of interest for $v$ has exactly one element,
24322
+ namely the declared type
24323
+ (\ref{localVariableDeclaration}).
24324
+ This is the stack of types of interest
24325
+ for the declaring occurrence of the name of $v$
24326
+ (\commentary{%
24327
+ i.e., the very first time the variable is mentioned, \ref{variables}%
24328
+ }).
24329
+
24327
24330
\LMHash{}%
24328
24331
If a local variable $v$ has an initializing expression
24329
24332
and does not have the modifier \FINAL,
@@ -24363,20 +24366,91 @@ \subsection{Type Promotion}
24363
24366
Consider the situation
24364
24367
where the declaration of a local variable $v$ is of the form
24365
24368
\code{\LATE?\,\,\VAR\,\,$v$ = $e$;}
24366
- where the static type of $e$ is of the form \code{$X$\,\&\,$T$}
24369
+ where the static type of $e$ is of the form \code{$X$\,\&\,\, $T$}
24367
24370
where $X$ is a type variable.
24368
24371
In this situation, the declared type of $v$ is \code{X}
24369
24372
(\ref{localVariableDeclaration}),
24370
- but the type \code{$X$\,\&\,$T$} is added to the stack of types of interest,
24371
- and the type of $v$ is immediately promoted to \code{$X$\,\&\,$T$}.
24373
+ but the type \code{$X$\,\&\,\, $T$} is added to the stack of types of interest,
24374
+ and the type of $v$ is immediately promoted to \code{$X$\,\&\,\, $T$}.
24372
24375
24373
24376
\commentary{%
24374
- Note that \code{$X$\,\&\,$T$} is not otherwise automatically a
24377
+ Note that \code{$X$\,\&\,\, $T$} is not otherwise automatically a
24375
24378
type of interest just because $X$ is a type of interest.
24376
24379
In particular, if $w$ is declared as
24377
24380
\code{\LATE?\,\,$X$\,\,$w$ = $e$;}
24378
- where the static type of $e$ is \code{$X$\,\&\,$T$},
24379
- the type of $w$ is \emph{not} immediately promoted to \code{$X$\,\&\,$T$}.%
24381
+ where the static type of $e$ is \code{$X$\,\&\,\,$T$},
24382
+ the type of $w$ is \emph{not} promoted to \code{$X$\,\&\,\,$T$}.%
24383
+ }
24384
+
24385
+ \LMHash{}%
24386
+ We now mention the locations where promotion may occur
24387
+ independently of the control flow.
24388
+
24389
+ \commentary{%
24390
+ We might say that these promotions are ``atomic'',
24391
+ and all other promotions are derived from these,
24392
+ and from the control flow.%
24393
+ }
24394
+
24395
+ \LMHash{}%
24396
+ Let $\ell$ be a location,
24397
+ and let $v$ be a local variable which is in scope at $\ell$.
24398
+ Assume that $\ell$ occurs after the declaration of $v$.
24399
+ The expressions that give rise to promotion or demotion
24400
+ of the type of $v$ at $\ell$
24401
+ are the following:
24402
+
24403
+ \begin{itemize}
24404
+ \item A type test of the form \code{$v$\,\,\IS\,\,$T$}.
24405
+ \item A type check of the form \code{$v$\,\,\AS\,\,$T$}.
24406
+ \item An assignment of the form \code{$v$\,\,=\,\,$e$}
24407
+ where the static type of $e$ is a type of interest for $v$ at $\ell$,
24408
+ and similarly for compound assignments
24409
+ (\ref{compoundAssignment})
24410
+ including \lit{??=}.
24411
+ \item An equality test of the form \code{$v$\,\,==\,\,$e$} or
24412
+ \code{$e$\,\,==\,\,$v$}, where $e$ is \NULL,
24413
+ optionally wrapped in one or more parentheses,
24414
+ and similarly for \lit{!=}.
24415
+ \end{itemize}
24416
+
24417
+ \LMHash{}%
24418
+ In particular,
24419
+ a check of the form \code{$v$\,\,==\,\,\NULL},
24420
+ \code{\NULL\,\,==\,\,$v$},
24421
+ or \code{$v$\,\,\IS\,\,Null}
24422
+ where $v$ has type $T$ at $\ell$
24423
+ promotes the type of $v$
24424
+ to \code{Null} in the \TRUE{} continuation,
24425
+ and to \NonNullType{$T$} in the \FALSE{} continuation.
24426
+
24427
+ \LMHash{}%
24428
+ %% TODO(eernst), for review: The null safety spec says that `T?` is
24429
+ %% promoted to `T`, but implementations _do_ promote `X extends int?` to
24430
+ %% `X & int`. So I specify that.
24431
+ A check of the form \code{$v$\,\,!=\,\,\NULL},
24432
+ \code{\NULL\,\,!=\,\,$v$},
24433
+ or \code{$v$\,\,\IS\,\,$T$}
24434
+ where $v$ has type $T$ at $\ell$
24435
+ promotes the type of $v$
24436
+ to \NonNullType{$T$} in the \TRUE{} continuation,
24437
+ and to \code{Null} in the \FALSE{} continuation.
24438
+
24439
+ \commentary{%
24440
+ The resulting type of $v$ may be the obvious one, e.g.,
24441
+ \code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
24442
+ but it may also give rise to a demotion
24443
+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
24444
+ and it may have no effect on the type of $v$
24445
+ (e.g., when the static type of $e$ is not a type of interest).
24446
+ These details will be specified in a future version of this specification.
24447
+
24448
+ Every non-trivial type of control flow determines the control flow graph,
24449
+ and the control flow graph determines which of the above
24450
+ may or must have occurred at $\ell$,
24451
+ and hence gives rise to the stack of types of interest of $v$ at $\ell$,
24452
+ which in turn determines the type of $v$ at $\ell$.
24453
+ This part of the flow analysis will also be specified in the future.%
24380
24454
}
24381
24455
24382
24456
@@ -24537,32 +24611,11 @@ \section{Null safety} %% !!!TODO!!!
24537
24611
%% !!!At the end: Search Null, change to Never where appropriate
24538
24612
%% !!!Search all `TODO`.*null
24539
24613
24540
- \subsubsection{Null promotion}
24541
- \LMLabel{}
24542
-
24543
- !!!
24544
-
24545
- The machinery of type promotion is extended to promote the type of
24546
- variables based on nullability checks subject to the same set of
24547
- restrictions as normal promotion. The relevant checks and the types
24548
- they are considered to promote to are as follows.
24549
-
24550
- A check of the form \code{$e$ == null} or of the form
24551
- \code{$e$\,\,\IS\,\,Null} where $e$ has static type $T$ promotes the
24552
- type of $e$ to \code{Null} in the \code{true} continuation, and to
24553
- \NonNullType{$T$} in the \code{false} continuation.
24554
-
24555
- A check of the form \code{$e$ != null} or of the form
24556
- \code{$e$\,\,\IS\,\,$T$} where $e$ has static type
24557
- \code{$T$?}\ promotes the type of $e$ to $T$ in the \code{true}
24558
- continuation, and to \code{Null} in the \code{false} continuation.
24559
-
24560
- The static type of an expression \code{$e$!} is \NonNullType{$T$}
24561
- where $T$ is the static type of $e$.
24562
-
24563
24614
\subsubsection{Null aware operator}
24564
24615
\LMLabel{nullShorteningTransformation}
24565
24616
24617
+ !!!
24618
+
24566
24619
The semantics of the null aware operator \code{?.} are defined via a source to source
24567
24620
translation of expressions into Dart code extended with a let binding construct.
24568
24621
The translation is defined using meta-level functions over syntax. We use the
0 commit comments