Now specifying void return type for setters and operator []=

Change-Id: Id2e8b3314eb5bba4ebf82286c0f8228db2235af0
Reviewed-on: https://dart-review.googlesource.com/32603
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
This commit is contained in:
Erik Ernst 2018-01-08 11:55:24 +01:00 committed by commit-bot@chromium.org
parent fa6fa059c4
commit dd3f935cf5

View file

@ -35,6 +35,7 @@
% - Update "FutureOr" specification for Dart 2.0.
% - Require that a top-level "main" declaration is a valid script-entry
% function declaration.
% - State that the return type of a setter or []= is void when not specified.
%
% 1.15
% - Change how language specification describes control flow.
@ -1021,7 +1022,9 @@ The static checker would of course flag such situations, but the consequence wou
\LMLabel{typeOfAFunction}
\LMHash{}
If a function does not declare a return type explicitly, its return type is \DYNAMIC{} (\ref{typeDynamic}), unless it is a constructor function, in which case its return type is the immediately enclosing class.
If a function does not declare a return type explicitly, its return type is \DYNAMIC{} (\ref{typeDynamic}),
unless it is a constructor function, in which case its return type is the immediately enclosing class,
or it is a setter or operator \code{[]=}, in which case its return type is \VOID{}.
\LMHash{}
Let $F$ be a function with required formal parameters $T_1$ $p_1 \ldots, T_n$ $p_n$, return type $T_0$ and no optional parameters.
@ -1298,6 +1301,10 @@ It is a compile-time error to declare an optional parameter in an operator.
\LMHash{}
It is a static warning if the return type of the user-declared operator \code{[]=} is explicitly declared and not \VOID{}.
\commentary{
If no return type is specified for a user-declared operator \code{[]=}, its return type is \VOID{} (\ref{typeOfAFunction}).
}
% add rationale: return in []= methods will have no effect, a the expression always returns its second argument (the RHS of the assignment, for consistency with assignment in general). So it's best to enforce this by declaring the method to be void, even though the expression that uses it returns an object with the type of the RHS, as described in \ref{assignment}.
@ -1366,8 +1373,9 @@ Setters are functions (\ref{functions}) that are used to set the values of objec
.
\end{grammar}
\LMHash{}
If no return type is specified, the return type of the setter is \DYNAMIC{}.
\commentary{
If no return type is specified, the return type of the setter is \VOID{} (\ref{typeOfAFunction}).
}
\LMHash{}
A setter definition that is prefixed with the \STATIC{} modifier defines a static setter.
@ -3657,7 +3665,7 @@ The static type of a function literal of the form
$(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{n+k} = d_k])$ \ASYNC{} $=> e$
is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarrow \code{Future<$flatten(T_0)$>}$, where $T_0$ is the static type of $e$and $flatten(T)$ is defined as follows:
If $T = FuturOr<S>$ then $flatten(T) = S$.
If $T = FutureOr<S>$ then $flatten(T) = S$.
Otherwise if $T <: Future$ then let $S$ be a type such that $T << Future<S>$ and for all $R$, if $T << Future<R>$ then $S << R$.