Skip to content

Commit

Permalink
Introduce \DynamicError, marking all dynamic errors just like compile…
Browse files Browse the repository at this point in the history
…-time errors have been for a while
  • Loading branch information
eernstg committed Feb 2, 2023
1 parent 18aa1e4 commit 9b4f226
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 39 deletions.
10 changes: 7 additions & 3 deletions specification/dart.sty
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@

% Used for defining occurrence of phrase, with customized index entry.
\newcommand{\IndexCustom}[2]{%
\leavevmode\marginpar{\ensuremath{_{^\vartriangle}}}\emph{#1}\index{#2}}
\leavevmode\marginpar{\ensuremath{\vartriangle}}\emph{#1}\index{#2}}

% Used for the defining occurrence of a local symbol.
\newcommand{\DefineSymbol}[1]{%
Expand All @@ -190,11 +190,15 @@

% Same appearance, but not adding an entry to the index.
\newcommand{\NoIndex}[1]{%
\leavevmode\marginpar{\ensuremath{_{^\vartriangle}}}\emph{#1}}
\leavevmode\marginpar{\ensuremath{\vartriangle}}\emph{#1}}

% Mark a compile-time error in the margin.
\newcommand{\Error}[1]{%
\leavevmode\marginpar{\ensuremath{_{^\ominus}}}{#1}}
\leavevmode\marginpar{\ensuremath{\ominus}}{#1}}

% Mark a dynamic error in the margin.
\newcommand{\DynamicError}[1]{%
\leavevmode\marginpar{\Lightning}{#1}}

% Used to specify comma separated lists of similar symbols.
\newcommand{\List}[3]{\ensuremath{{#1}_{#2},\,\ldots,\ {#1}_{#3}}}
Expand Down
94 changes: 58 additions & 36 deletions specification/dartLangSpec.tex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
\usepackage[T1]{fontenc}
\usepackage{makeidx}
\usepackage{enumitem}
\usepackage{marvosym}
\makeindex
\title{Dart Programming Language Specification\\
{6th edition draft}\\
Expand All @@ -36,6 +37,10 @@
% version of the language which will actually be specified by the next stable
% release of this document.
%
% Jan, Feb 2023
% - Introduce `\DynamicError{}`, thus marking every introduction (definition)
% of a dynamic error by a lightning symbol in the right margin.
%
% Dec 2022
% - Change the definition of the type function 'flatten' to resolve soundness
% issue, cf. SDK issue #49396.
Expand Down Expand Up @@ -1464,7 +1469,7 @@ \subsection{Implicitly Induced Getters and Setters}
it will bind \id{} to the object that $x$ is bound to.
If this setter is executed
in a situation where the variable \id{} has been bound to an object,
a dynamic error occurs.
a \DynamicError{dynamic error} occurs.

\commentary{%
A late final variable declaration with no initializer is permitted.
Expand Down Expand Up @@ -1505,7 +1510,7 @@ \subsection{Implicitly Induced Getters and Setters}
will bind \id{} to the object that the argument $x$ is bound to.
An execution of the setter
in a situation where the variable \id{} has been bound to an object
will incur a dynamic error.
will incur a \DynamicError{dynamic error}.

\LMHash{}%
The scope into which the implicit getters and setters are introduced
Expand Down Expand Up @@ -1559,7 +1564,7 @@ \subsection{Implicitly Induced Getters and Setters}
but initialization and assignment is not the same thing.
When the receiver has type \DYNAMIC{}
such an assignment is not a compile-time error,
but if there is no such setter it will cause a dynamic error.%
but if there is no such setter it will cause a \DynamicError{dynamic error}.%
}

\LMHash{}%
Expand Down Expand Up @@ -1681,7 +1686,7 @@ \subsection{Evaluation of Implicit Variable Getters}
will evaluate to the object that \id{} is bound to.
Otherwise
(\commentary{when this variable has never been bound}),
the getter invocation incurs a dynamic error.
the getter invocation incurs a \DynamicError{dynamic error}.
\EndCase

\LMHash{}%
Expand Down Expand Up @@ -1788,7 +1793,7 @@ \subsection{Evaluation of Implicit Variable Getters}
will complete returning $o$.
An execution of the implicitly induced getter of \id{}
in a situation where the variable \id{} is unbound
will incur a dynamic error.
will incur a \DynamicError{dynamic error}.
\end{itemize}

% Reduce whitespace after itemized list: This is just an end symbol.
Expand Down Expand Up @@ -3996,7 +4001,7 @@ \subsubsection{Generative Constructors}
% This can occur due to a failing implicit cast.
unless the assigned object has a dynamic type
which is not a subtype of the declared type of the instance variable \id,
in which case a dynamic error occurs.
in which case a \DynamicError{dynamic error} occurs.

\commentary{%
The above rule allows initializing formals to be used as optional parameters:%
Expand Down Expand Up @@ -10281,7 +10286,7 @@ \subsubsection{Collection Literal Element Evaluation}
or the given \code{value} does not have the type \code{Value},
but it cannot occur after the pair has been appended to $s$.
\item
Otherwise, a dynamic error occurs.
Otherwise, a \DynamicError{dynamic error} occurs.

\commentary{%
This occurs when the target is an iterable respectively a map,
Expand Down Expand Up @@ -10336,7 +10341,8 @@ \subsubsection{Collection Literal Element Evaluation}
and if $\ell_2$ is not present then
$\EvaluateElement{\ell} := \LiteralSequence{}$.
% $o_b$ can have type \DYNAMIC.
If $o_b$ is neither \TRUE{} nor \FALSE{} then a dynamic error occurs.
If $o_b$ is neither \TRUE{} nor \FALSE{}
then a \DynamicError{dynamic error} occurs.
\EndCase

\LMHash{}%
Expand Down Expand Up @@ -10567,7 +10573,7 @@ \subsubsection{Lists}
An empty list has an empty set of indices.
A non-empty list has the index set $\{0, \ldots, n - 1\}$
where $n$ is the size of the list.
It is a dynamic error to attempt to access a list
It is a \DynamicError{dynamic error} to attempt to access a list
using an index that is not a member of its set of indices.

\rationale{%
Expand All @@ -10591,7 +10597,8 @@ \subsubsection{Lists}
Only run-time list literals can be mutated
after they are created.
% This error can occur because being constant is a dynamic property.
Attempting to mutate a constant list literal will result in a dynamic error.
Attempting to mutate a constant list literal
will result in a \DynamicError{dynamic error}.

\commentary{%
% The following is true either directly or indirectly: There is a \CONST{}
Expand Down Expand Up @@ -11360,7 +11367,7 @@ \subsubsection{Sets}
\LMHash{}%
A set may contain zero or more objects.
Sets have a method which can be used to insert objects;
this will incur a dynamic error if the set is not modifiable.
this will incur a \DynamicError{dynamic error} if the set is not modifiable.
Otherwise, when inserting an object $o_{\metavar{new}}$ into a set $s$,
if an object $o_{\metavar{old}}$ exists in $s$ such that
\code{$o_{\metavar{old}}$ == $o_{\metavar{new}}$} evaluates to \TRUE{}
Expand Down Expand Up @@ -11400,7 +11407,8 @@ \subsubsection{Sets}
and it is evaluated at run time.
Only run-time set literals can be mutated after they are created.
% This error can occur because being constant is a dynamic property, here.
Attempting to mutate a constant set literal will result in a dynamic error.
Attempting to mutate a constant set literal
will result in a \DynamicError{dynamic error}.

\commentary{%
% The following is true either directly or indirectly: There is a \CONST{}
Expand Down Expand Up @@ -11606,7 +11614,8 @@ \subsubsection{Maps}
and it is evaluated at run time.
Only run-time map literals can be mutated after they are created.
% This error can occur because being constant is a dynamic property, here.
Attempting to mutate a constant map literal will result in a dynamic error.
Attempting to mutate a constant map literal
will result in a \DynamicError{dynamic error}.

\commentary{%
% The following is true either directly or indirectly: There is a \CONST{}
Expand Down Expand Up @@ -11747,7 +11756,8 @@ \subsection{Throw}
}

\LMHash{}%
If $v$ is the null object (\ref{null}), then a dynamic error occurs.
If $v$ is the null object (\ref{null})
then a \DynamicError{dynamic error} occurs.
Otherwise let $t$ be a stack trace corresponding to the current execution state,
and the \THROW{} statement throws with $v$ as exception object
and $t$ as stack trace (\ref{expressionEvaluation}).
Expand Down Expand Up @@ -12261,7 +12271,7 @@ \subsubsection{New}
% This error can occur because being-loaded is a dynamic property.
If $T$ is a deferred type with prefix $p$,
then if $p$ has not been successfully loaded,
a dynamic error occurs.
a \DynamicError{dynamic error} occurs.
\EndCase

\LMHash{}%
Expand Down Expand Up @@ -13189,7 +13199,7 @@ \subsubsection{Binding Actuals to Formals}
If $r = 0$ and $s > 0$ then
if $f$ does not have default type arguments
(\ref{instantiationToBound})
then a dynamic error occurs.
then a \DynamicError{dynamic error} occurs.
Otherwise replace the actual type argument list:
Let $r$ be $s$ and let $t_i$ for $i \in 1 .. s$ be the result of
instantiation to bound
Expand Down Expand Up @@ -16154,7 +16164,8 @@ \subsection{Assignment}
in which case $v$ has no initializer and is not definitely assigned,
or a compile-time error would have occurred%
}).
If $v$ has previously been bound to an object then a dynamic error occurs.
If $v$ has previously been bound to an object
then a \DynamicError{dynamic error} occurs.
Otherwise, $v$ is bound to $o$, and then $a$ evaluates to $o$
(\ref{expressionEvaluation}).
\item
Expand Down Expand Up @@ -16706,7 +16717,8 @@ \subsection{Conditional}
proceeds as follows:
Evaluate $e_1$ to an object $o_1$.
% This error can occur due to an implicit cast from \DYNAMIC.
It is a dynamic error if the run-time type of $o_1$ is not \code{bool}.
It is a \DynamicError{dynamic error}
if the run-time type of $o_1$ is not \code{bool}.
If $o_1$ is the \TRUE{} object, then the value of $c$ is
the result of evaluating the expression $e_2$.
Otherwise, the value of $c$ is the result of evaluating the expression $e_3$.
Expand Down Expand Up @@ -16774,23 +16786,27 @@ \subsection{Logical Boolean Expressions}
\code{$e_1$\,\,||\,\,$e_2$}
causes the evaluation of $e_1$ to an object $o_1$.
% This error can occur due to an implicit downcast from \DYNAMIC.
It is a dynamic error if the run-time type of $o_1$ is not \code{bool}.
It is a \DynamicError{dynamic error}
if the run-time type of $o_1$ is not \code{bool}.
If $o_1$ is \TRUE, the result of evaluating $b$ is \TRUE,
otherwise $e_2$ is evaluated to an object $o_2$.
% This error can occur due to an implicit downcast from \DYNAMIC.
It is a dynamic error if the run-time type of $o_2$ is not \code{bool}.
It is a \DynamicError{dynamic error}
if the run-time type of $o_2$ is not \code{bool}.
Otherwise the result of evaluating $b$ is $o_2$.

\LMHash{}%
Evaluation of a logical boolean expression $b$ of the form
\code{$e_1$\,\,\&\&\,\,$e_2$}
causes the evaluation of $e_1$ to an object $o_1$.
% This error can occur due to an implicit downcast from \DYNAMIC.
It is a dynamic error if the run-time type of $o_1$ is not \code{bool}.
It is a \DynamicError{dynamic error}
if the run-time type of $o_1$ is not \code{bool}.
If $o_1$ is \FALSE, the result of evaluating $b$ is \FALSE,
otherwise $e_2$ is evaluated to an object $o_2$.
% This error can occur due to an implicit downcast from \DYNAMIC.
It is a dynamic error if the run-time type of $o_2$ is not \code{bool}.
It is a \DynamicError{dynamic error}
if the run-time type of $o_2$ is not \code{bool}.
Otherwise the result of evaluating $b$ is $o_2$.


Expand Down Expand Up @@ -17325,7 +17341,7 @@ \subsection{Postfix Expressions}

\LMHash{}%
$e$ is evaluated as follows: $e_1$ is evaluated to an object $o$.
If $o$ is the null object then a dynamic error occurs,
If $o$ is the null object then a \DynamicError{dynamic error} occurs,
otherwise $e$ evaluates to $o$.
\EndCase

Expand Down Expand Up @@ -18655,7 +18671,7 @@ \subsection{Local Variable Declaration}
then $v$ is bound to $o$.
If an object $o$ is assigned to $v$
in a situation where $v$ is bound to an object $o'$
then a dynamic error occurs
then a \DynamicError{dynamic error} occurs
(\commentary{it does not matter whether $o$ is the same object as $o'$}).

\commentary{%
Expand Down Expand Up @@ -18816,7 +18832,8 @@ \subsection{If}
proceeds as follows:
Evaluate the expression $e$ to an object $o$.
% This error can occur due to an implicit downcast from \DYNAMIC.
It is a dynamic error if the run-time type of $o$ is not \code{bool}.
It is a \DynamicError{dynamic error}
if the run-time type of $o$ is not \code{bool}.
If $o$ is \TRUE, then execute the block statement $S_1$,
otherwise execute the block statement $S_2$.

Expand Down Expand Up @@ -18899,7 +18916,8 @@ \subsubsection{For Loop}
\item
The expression $[v'/v]c$ is evaluated to an object $o$.
% This error can occur due to an implicit downcast from \DYNAMIC.
It is a dynamic error if the run-time type of $o$ is not \code{bool}.
It is a \DynamicError{dynamic error}
if the run-time type of $o$ is not \code{bool}.
If $o$ is \FALSE, the for loop completes normally.
Otherwise, execution continues at step \ref{beginIteration}.
\item
Expand Down Expand Up @@ -19109,7 +19127,8 @@ \subsection{While}
\LMHash{}%
The expression $e$ is evaluated to an object $o$.
% This error can occur due to an implicit downcast from \DYNAMIC.
It is a dynamic error if the run-time type of $o$ is not \code{bool}.
It is a \DynamicError{dynamic error}
if the run-time type of $o$ is not \code{bool}.

\LMHash{}%
If $o$ is \FALSE, then execution of the while statement completes normally
Expand Down Expand Up @@ -19160,7 +19179,8 @@ \subsection{Do}
\LMHash{}%
Then, the expression $e$ is evaluated to an object $o$.
% This error can occur due to an implicit downcast from \DYNAMIC.
It is a dynamic error if the run-time type of $o$ is not \code{bool}.
It is a \DynamicError{dynamic error}
if the run-time type of $o$ is not \code{bool}.
If $o$ is \FALSE, execution of the do statement completes normally
(\ref{statementCompletion}).
If $o$ is \TRUE, then the do statement is re-executed.
Expand Down Expand Up @@ -19851,7 +19871,8 @@ \subsection{Return}

\LMHash{}%
The expression $e$ is evaluated to an object $o$.
A dynamic error occurs unless the dynamic type of $o$ is a subtype of
A \DynamicError{dynamic error} occurs
unless the dynamic type of $o$ is a subtype of
the actual return type of $f$
(\ref{actualTypes}).
Then the return statement $s$ completes returning $o$
Expand All @@ -19878,7 +19899,8 @@ \subsection{Return}
let \code{v} be a fresh variable bound to $o$ and
evaluate \code{\AWAIT{} v} to an object $r$;
otherwise let $r$ be $o$.
A dynamic error occurs unless the dynamic type of $r$
A \DynamicError{dynamic error} occurs
unless the dynamic type of $r$
is a subtype of the actual value of $T_v$
(\ref{actualTypes}).
Then the return statement $s$ completes returning $r$
Expand Down Expand Up @@ -20763,28 +20785,28 @@ \subsubsection{Semantics of Imports}
\NamespaceName{\metavar{import},i},
a corresponding function named \id{} with the same function header as $f$.
% This error can occur because being-loaded is a dynamic property.
Calling the function results in a dynamic error,
Calling the function results in a \DynamicError{dynamic error},
and so does closurizing it
(\ref{functionClosurization}).
\item
For every top level getter $g$ named \id{} in
\NamespaceName{\metavar{import},i},
a corresponding getter named \id{} with the same function header as $g$.
% This error can occur because being-loaded is a dynamic property.
Calling the getter results in a dynamic error.
Calling the getter results in a \DynamicError{dynamic error}.
\item
For every top level setter $s$ named \code{\id=} in
\NamespaceName{\metavar{import},i},
a corresponding setter named \code{\id=} with
the same function header as $s$.
% This error can occur because being-loaded is a dynamic property.
Calling the setter results in a dynamic error.
Calling the setter results in a \DynamicError{dynamic error}.
\item
For every class, mixin and type alias declaration named \id{} in
\NamespaceName{\metavar{import},i},
a corresponding getter named \id{} with return type \code{Type}.
% This error can occur because being-loaded is a dynamic property.
Calling the getter results in a dynamic error.
Calling the getter results in a \DynamicError{dynamic error}.
\end{itemize}

\rationale{%
Expand Down Expand Up @@ -21318,7 +21340,7 @@ \subsection{Scripts}
that spawned $i$%
}),
or the null object if no such object was supplied.
A dynamic error occurs if
A \DynamicError{dynamic error} occurs if
the run-time type of this object is not a subtype of
the declared type of the corresponding parameter of \code{main}.
\end{itemize}
Expand All @@ -21341,7 +21363,7 @@ \subsection{Scripts}
(\commentary{%
the above rules ensure that the corresponding parameters are optional%
}).
But the implementation must ensure that a dynamic error occurs
But the implementation must ensure that a \DynamicError{dynamic error} occurs
if an actual argument does not have a run-time type which is
a subtype of the declared type of the parameter.

Expand Down

0 comments on commit 9b4f226

Please sign in to comment.