Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Side by Side Diff: docs/language/dartLangSpec.tex

Issue 2873313003: Make void-arrow-functions statically accept any expression type. (Closed)
Patch Set: Address comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 \documentclass{article} 1 \documentclass{article}
2 \usepackage{epsfig} 2 \usepackage{epsfig}
3 \usepackage{color} 3 \usepackage{color}
4 \usepackage{dart} 4 \usepackage{dart}
5 \usepackage{bnf} 5 \usepackage{bnf}
6 \usepackage{hyperref} 6 \usepackage{hyperref}
7 \usepackage{lmodern} 7 \usepackage{lmodern}
8 \usepackage[T1]{fontenc} 8 \usepackage[T1]{fontenc}
9 \newcommand{\code}[1]{{\sf #1}} 9 \newcommand{\code}[1]{{\sf #1}}
10 \title{Dart Programming Language Specification \\ 10 \title{Dart Programming Language Specification \\
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 . 607 .
608 608
609 \end{grammar} 609 \end{grammar}
610 610
611 \LMHash{} 611 \LMHash{}
612 Functions include function declarations (\ref{functionDeclarations}), methods ( \ref{instanceMethods}, \ref{staticMethods}), getters (\ref{getters}), setters (\ref{setters}), constructors (\ref{constructors}) and function literals (\re f{functionExpressions}). 612 Functions include function declarations (\ref{functionDeclarations}), methods ( \ref{instanceMethods}, \ref{staticMethods}), getters (\ref{getters}), setters (\ref{setters}), constructors (\ref{constructors}) and function literals (\re f{functionExpressions}).
613 613
614 \LMHash{} 614 \LMHash{}
615 All functions have a signature and a body. The signature describes the formal pa rameters of the function, and possibly its name and return type. A function bod y is either: 615 All functions have a signature and a body. The signature describes the formal pa rameters of the function, and possibly its name and return type. A function bod y is either:
616 \begin{itemize} 616 \begin{itemize}
617 \item A block statement (\ref{blocks}) containing the statements (\ref{stateme nts}) executed by the function, optionally marked with one of the modifiers: \AS YNC, \ASYNC* or \SYNC*. In this case, if the last statement of a function is not a return statement (\ref{return}), the statement \code{\RETURN{};} is implicitl y appended to the function body. 617 \item A block statement (\ref{blocks}) containing the statements (\ref{statement s}) executed by the function, optionally marked with one of the modifiers: \ASYN C, \ASYNC* or \SYNC*.
618 618
619 \rationale{ 619 \commentary{
620 Because Dart is optionally typed, we cannot guarantee that a function that does not return a value will not be used in the context of an expression. Therefore, every function must return a value. A \RETURN{} without an expression returns \N ULL{}. For generator functions, the situation is more subtle. See further discus sion in section \ref{return}. 620 Because Dart is optionally typed, we cannot guarantee that a function that does not return a value will not be used in the context of an expression. Therefore, every function must return a value. A function body that ends without doing a th row or return will cause the function to return \NULL{}, as will a \RETURN{} wit hout an expression. For generator functions, the situation is more subtle. See f urther discussion in section \ref{return}.
621 } 621 }
622 622
623 OR 623 OR
624 \item of the form \code{=> $e$} which is equivalent to a body of the form \cod e{\{\RETURN{} $e$;\}} or the form \code{\ASYNC{} => $e$} which is equivalent to a body of the form \code{\ASYNC{} \{\RETURN{} $e$;\}}. \rationale{The other modi fiers do not apply here, because they apply only to generators, discussed below, and generators do not allow the form \code{\RETURN{} $e$}; values are added to the generated stream or iterable using \YIELD{} instead.} 624 \item of the form \code{=> $e$} or the form \code{\ASYNC{} => $e$}, which both r eturn the value of the expression $e$ as if by a \code{return $e$}. \commentary{ The other modifiers do not apply here, because they apply only to generators, di scussed below, and generators do not allow to return a value, values are added t o the generated stream or iterable using \YIELD{} instead.}
625 }
626 Let $R$ be the static type of $e$
627 and let $T$ be the actual return type (\ref{actualTypeOfADeclaration})
628 of the function that has this body.
629 It is a static warning if $T$ is not \VOID{} and either
630 the function is synchronous and the static type of $R$ is not assignable to $T$,
631 or the function is asynchronous and \code{Future<$flatten${$R$}>}
632 is not assignable to $T$.
625 633
626 \end{itemize} 634 \end{itemize}
627 635
628 \LMHash{} 636 \LMHash{}
629 A function is {\em asynchronous} if its body is marked with the \ASYNC{} or \ASY NC* modifier. Otherwise the function is {\em synchronous}. A function is a {\em generator} if its body is marked with the \SYNC* or \ASYNC* modifier. 637 A function is {\em asynchronous} if its body is marked with the \ASYNC{} or \ASY NC* modifier. Otherwise the function is {\em synchronous}. A function is a {\em generator} if its body is marked with the \SYNC* or \ASYNC* modifier.
630 638
631 \commentary{ 639 \commentary{
632 Whether a function is synchronous or asynchronous is orthogonal to whether it is a generator or not. Generator functions are a sugar for functions that produce collections in a systematic way, by lazily applying a function that {\em generat es} individual elements of a collection. Dart provides such a sugar in both the synchronous case, where one returns an iterable, and in the asynchronous case, w here one returns a stream. Dart also allows both synchronous and asynchronous fu nctions that produce a single value. 640 Whether a function is synchronous or asynchronous is orthogonal to whether it is a generator or not. Generator functions are a sugar for functions that produce collections in a systematic way, by lazily applying a function that {\em generat es} individual elements of a collection. Dart provides such a sugar in both the synchronous case, where one returns an iterable, and in the asynchronous case, w here one returns a stream. Dart also allows both synchronous and asynchronous fu nctions that produce a single value.
633 } 641 }
634 642
(...skipping 3074 matching lines...) Expand 10 before | Expand all | Expand 10 after
3709 3717
3710 3718
3711 3719
3712 \subsection{ Function Invocation} 3720 \subsection{ Function Invocation}
3713 \LMLabel{functionInvocation} 3721 \LMLabel{functionInvocation}
3714 3722
3715 \LMHash{} 3723 \LMHash{}
3716 Function invocation occurs in the following cases: when a function expression ( \ref{functionExpressions}) is invoked (\ref{functionExpressionInvocation}), when a method (\ref{methodInvocation}), getter (\ref{topLevelGetterInvocation}, \ref {propertyExtraction}) or setter (\ref{assignment}) is invoked or when a construc tor is invoked (either via instance creation (\ref{instanceCreation}), construct or redirection (\ref{redirectingConstructors}) or super initialization). The var ious kinds of function invocation differ as to how the function to be invoked, $ f$, is determined, as well as whether \THIS{} (\ref{this}) is bound. Once $f$ h as been determined, the formal parameters of $f$ are bound to corresponding actu al arguments. When the body of $f$ is executed it will be executed with the afor ementioned bindings. 3724 Function invocation occurs in the following cases: when a function expression ( \ref{functionExpressions}) is invoked (\ref{functionExpressionInvocation}), when a method (\ref{methodInvocation}), getter (\ref{topLevelGetterInvocation}, \ref {propertyExtraction}) or setter (\ref{assignment}) is invoked or when a construc tor is invoked (either via instance creation (\ref{instanceCreation}), construct or redirection (\ref{redirectingConstructors}) or super initialization). The var ious kinds of function invocation differ as to how the function to be invoked, $ f$, is determined, as well as whether \THIS{} (\ref{this}) is bound. Once $f$ h as been determined, the formal parameters of $f$ are bound to corresponding actu al arguments. When the body of $f$ is executed it will be executed with the afor ementioned bindings.
3717 3725
3718 \LMHash{} 3726 \LMHash{}
3727 Executing a body of the form \code{=> $e$} is equivalent to executing a body of the form \code{\{ return $e$; \}}.
3728 Execution a body of the form \code{async => $e$} is equivalent to executing a bo dy of the form \code{async \{ return $e$; \}}.
3729
3730 \LMHash{}
3719 If $f$ is synchronous and is not a generator (\ref{functions}) then execution of the body of $f$ begins immediately. 3731 If $f$ is synchronous and is not a generator (\ref{functions}) then execution of the body of $f$ begins immediately.
3720 If the execution of the body of $f$ returns a value, $v$, (\ref{completion}), th e invocation evaluates to $v$. 3732 If the execution of the body of $f$ returns a value, $v$, (\ref{completion}), th e invocation evaluates to $v$.
3721 If the execution completes normally or it returns without a value, the invocatio n evaluates to \NULL (\ref{null}). 3733 If the execution completes normally or it returns without a value, the invocatio n evaluates to \NULL (\ref{null}).
3722 If the execution throws an exception object and stack trace, the invocation thro ws the same exception object and stack trace (\ref{evaluation}). 3734 If the execution throws an exception object and stack trace, the invocation thro ws the same exception object and stack trace (\ref{evaluation}).
3723 3735
3724 \commentary{ 3736 \commentary{
3725 A complete function body can never break or contine (\ref{completion}) 3737 A complete function body can never break or contine (\ref{completion})
3726 because a \BREAK{} or \CONTINUE{} statement must always occur inside the stateme nt that is the target of the \BREAK{} or \CONTINUE{}. 3738 because a \BREAK{} or \CONTINUE{} statement must always occur inside the stateme nt that is the target of the \BREAK{} or \CONTINUE{}.
3727 This means that a function body can only either complete normally, throw, or ret urn. Completing normally or returning without a value is treated the same as ret urning \NULL, so the result of executing a function body can always be used as t he result of evaluating an expression, either by evaluating to a value or by the evaluation throwing. 3739 This means that a function body can only either complete normally, throw, or ret urn. Completing normally or returning without a value is treated the same as ret urning \NULL, so the result of executing a function body can always be used as t he result of evaluating an expression, either by evaluating to a value or by the evaluation throwing.
3728 } 3740 }
(...skipping 2720 matching lines...) Expand 10 before | Expand all | Expand 10 after
6449 Executing a return statement \code{\RETURN{} $e$;} proceeds as follows: 6461 Executing a return statement \code{\RETURN{} $e$;} proceeds as follows:
6450 6462
6451 \LMHash{} 6463 \LMHash{}
6452 First the expression $e$ is evaluated, producing an object $o$. 6464 First the expression $e$ is evaluated, producing an object $o$.
6453 Then the return statement returns the value $o$ (\ref{completion}). 6465 Then the return statement returns the value $o$ (\ref{completion}).
6454 6466
6455 \LMHash{} 6467 \LMHash{}
6456 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion. 6468 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion.
6457 6469
6458 \LMHash{} 6470 \LMHash{}
6459 It is a static type warning if the body of $f$ is marked \ASYNC{} and the type \ code{Future<flatten(T)>} (\ref{functionExpressions}) may not be assigned to the declared return type of $f$. Otherwise, it is a static type warning if $T$ ma y not be assigned to the declared return type of $f$. 6471 It is a static type warning if the body of $f$ is marked \ASYNC{} and the type \ code{Future<$flatten$(T)>} (\ref{functionExpressions}) may not be assigned to th e declared return type of $f$. Otherwise, it is a static type warning if $T$ may not be assigned to the declared return type of $f$.
6460 6472
6461 \LMHash{} 6473 \LMHash{}
6462 Let $S$ be the runtime type of $o$. In checked mode: 6474 Let $S$ be the runtime type of $o$. In checked mode:
6463 \begin{itemize} 6475 \begin{itemize}
6464 \item If the body of $f$ is marked \ASYNC{} (\ref{functions}) 6476 \item If the body of $f$ is marked \ASYNC{} (\ref{functions})
6465 it is a dynamic type error if $o$ is not \NULL{} (\ref{null}), 6477 it is a dynamic type error if $o$ is not \NULL{} (\ref{null}),
6466 the actual return type (\ref{actualTypeOfADeclaration}) of $f$ is not \VOID, 6478 the actual return type (\ref{actualTypeOfADeclaration}) of $f$ is not \VOID,
6467 and \code{Future<flatten(S)>} is not a subtype of the actual return type of $f$. 6479 and \code{Future<$flatten$(S)>} is not a subtype of the actual return type of $f $.
6468 % TODO(lrn): The "void foo() async { return e }" case is somewhat speculative. 6480 % TODO(lrn): The "void foo() async { return e }" case is somewhat speculative.
6469 % When we disallow "return e" in a void function, we might also want to revisit 6481 % When we disallow "return e" in a void function, we might also want to revisit
6470 % this rule. Currently it also covers the "void foo() async => e;" case, which 6482 % this rule. Currently it also covers the "void foo() async => e;" case, which
6471 % we might want to allow. 6483 % we might want to allow.
6472 \item Otherwise, it is a dynamic type error if $o$ is not \NULL{}, 6484 \item Otherwise, it is a dynamic type error if $o$ is not \NULL{},
6473 the actual return type of $f$ is not \VOID{}, 6485 the actual return type of $f$ is not \VOID{},
6474 and the runtime type of $o$ is not a subtype of the actual return type of $f$. 6486 and the runtime type of $o$ is not a subtype of the actual return type of $f$.
6475 \end{itemize} 6487 \end{itemize}
6476 6488
6477 \LMHash{} 6489 \LMHash{}
(...skipping 1688 matching lines...) Expand 10 before | Expand all | Expand 10 after
8166 8178
8167 The invariant that each normative paragraph is associated with a line 8179 The invariant that each normative paragraph is associated with a line
8168 containing the text \LMHash{} should be maintained. Extra occurrences 8180 containing the text \LMHash{} should be maintained. Extra occurrences
8169 of \LMHash{} can be added if needed, e.g., in order to make 8181 of \LMHash{} can be added if needed, e.g., in order to make
8170 individual \item{}s in itemized lists addressable. Each \LM.. command 8182 individual \item{}s in itemized lists addressable. Each \LM.. command
8171 must occur on a separate line. \LMHash{} must occur immediately 8183 must occur on a separate line. \LMHash{} must occur immediately
8172 before the associated paragraph, and \LMLabel must occur immediately 8184 before the associated paragraph, and \LMLabel must occur immediately
8173 after the associated \section{}, \subsection{} etc. 8185 after the associated \section{}, \subsection{} etc.
8174 8186
8175 ---------------------------------------------------------------------- 8187 ----------------------------------------------------------------------
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698