From 9b4f226173bf92d5d40eba2444e38af24fdee058 Mon Sep 17 00:00:00 2001 From: Erik Ernst Date: Thu, 2 Feb 2023 13:49:21 +0100 Subject: [PATCH] Introduce \DynamicError, marking all dynamic errors just like compile-time errors have been for a while --- specification/dart.sty | 10 ++-- specification/dartLangSpec.tex | 94 +++++++++++++++++++++------------- 2 files changed, 65 insertions(+), 39 deletions(-) diff --git a/specification/dart.sty b/specification/dart.sty index 0bcb6e5466..72ec7e2966 100644 --- a/specification/dart.sty +++ b/specification/dart.sty @@ -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]{% @@ -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}}} diff --git a/specification/dartLangSpec.tex b/specification/dartLangSpec.tex index c0304a322d..1f2bc78d0f 100644 --- a/specification/dartLangSpec.tex +++ b/specification/dartLangSpec.tex @@ -12,6 +12,7 @@ \usepackage[T1]{fontenc} \usepackage{makeidx} \usepackage{enumitem} +\usepackage{marvosym} \makeindex \title{Dart Programming Language Specification\\ {6th edition draft}\\ @@ -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. @@ -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. @@ -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 @@ -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{}% @@ -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{}% @@ -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. @@ -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:% @@ -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, @@ -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{}% @@ -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{% @@ -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{} @@ -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{} @@ -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{} @@ -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{} @@ -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}). @@ -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{}% @@ -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 @@ -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 @@ -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$. @@ -16774,11 +16786,13 @@ \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{}% @@ -16786,11 +16800,13 @@ \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 \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$. @@ -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 @@ -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{% @@ -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$. @@ -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 @@ -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 @@ -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. @@ -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$ @@ -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$ @@ -20763,7 +20785,7 @@ \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 @@ -20771,20 +20793,20 @@ \subsubsection{Semantics of Imports} \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{% @@ -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} @@ -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.