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