Skip to content

Commit b441d93

Browse files
committed
Adjust specification of evaluation order for instance methods
1 parent 4b709f4 commit b441d93

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

specification/dartLangSpec.tex

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
% that `o` is desugared as `o.call` when the context type is a function type.
3737
% - Clarify the treatment of `covariant` parameters in the interface of a class
3838
% that inherits an implementation where those parameters are not covariant.
39+
% - Change the specified evaluation order for class instance methods such that
40+
% `x.m(a)` will evaluate `a` before calling `x.m`, which is observable in
41+
% the case where `x.m` is a getter with side effects.
3942
%
4043
% 2.14
4144
% - Add constraint on type of parameter which is covariant-by-declaration in
@@ -13703,7 +13706,7 @@ \subsubsection{Ordinary Invocation}
1370313706
Otherwise, let $d$ be the result of getter lookup
1370413707
for $m$ in $T$ with respect to $L$,
1370513708
and let $F$ be the return type of $d$.
13706-
(\commentary{
13709+
(\commentary{%
1370713710
Since \code{$T$.$m$} exists we cannot have a failure in both lookups.%
1370813711
})
1370913712
If the getter return type $F$ is an interface type
@@ -13787,12 +13790,34 @@ \subsubsection{Ordinary Invocation}
1378713790
$m$ in $o$ with respect to $L$.
1378813791

1378913792
\LMHash{}%
13790-
If the getter lookup succeeded then invoke the getter $o.m$
13791-
and let $v_g$ be the returned object.
13792-
Then the value of $i$ is the value of
13793+
If the getter lookup succeeded then evaluate the actual argument list
13794+
13795+
\noindent
13796+
\code{($a_1, \ldots,\ a_n,\ x_{n+1}$:\ $a_{n+1}, \ldots,\ x_{n+k}$:\ $a_{n+k}$)}
1379313797

1379413798
\noindent
13795-
\code{$v_g$<$A_1, \ldots,\ A_r$>($a_1,\ \ldots,\ a_n,\ x_{n+1}$: $a_{n+1},\ \ldots,\ x_{n+k}$: $a_{n+k}$)}.
13799+
in textual order to a sequence of objects $o_1, \ldots,\ o_{n+k}$,
13800+
and let \List{v}{1}{n+k} be fresh variables
13801+
such that $v_j$ is bound to $o_j$ for each $j \in 1 .. n+k$.
13802+
Then invoke the getter $o.m$ and let $v_g$ be the returned object.
13803+
The value of $i$ is then the value of
13804+
13805+
\noindent
13806+
\code{$v_g$<$A_1, \ldots,\ A_r$>($v_1,\ \ldots,\ v_n,\ x_{n+1}$:\ $v_{n+1},\ \ldots,\ x_{n+k}$:\ $v_{n+k}$)}.
13807+
13808+
\rationale{%
13809+
Note that this evaluation order is inconsistent with the general rule that
13810+
expressions are evaluated left-to-right
13811+
(unless the expression has a non-trivial control flow, e.g.,
13812+
\code{$e_1$\,?\,$e_2$\,:\,$e_3$}).
13813+
In particular all other function invocations use left-to-right evaluation,
13814+
including extension instance method invocations.
13815+
The reason for this inconsistency is mainly historical:
13816+
This evaluation order has been used for instance methods since the beginning of
13817+
the development of the language,
13818+
and it was not considered worthwhile to handle the breakage.
13819+
Another reason is that it allows for improved performance in some situations.%
13820+
}
1379613821

1379713822
\LMHash{}%
1379813823
If getter lookup has also failed,

0 commit comments

Comments
 (0)