diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-08-19 10:23:11 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-08-19 10:36:44 +0200 |
commit | 6634d82f74b71dd36ca1ecceea08b4ad79335da0 (patch) | |
tree | 91c1603918f24bd3075e2bda155cc6d4c85e6431 /test/files/neg/t1980.scala | |
parent | 5084b74048f7f21f38fdf45ebfa8e634b863bb01 (diff) | |
download | scala-6634d82f74b71dd36ca1ecceea08b4ad79335da0.tar.gz scala-6634d82f74b71dd36ca1ecceea08b4ad79335da0.tar.bz2 scala-6634d82f74b71dd36ca1ecceea08b4ad79335da0.zip |
SI-1980 A lint warning for by-name parameters in right assoc methods
The desugaring of right associative calls happens in the parser. This
eagerly evaluates the arguments (to preserve left-to-right evaluation
order the arguments are evaluated before the qualifier).
This is pretty surprising if the method being called has a by-name
parameter in the first parameter section.
This commit adds a warning under -Xlint when defining such a method.
The relevent spec snippets:
> SLS 4.6.1 says that call-by-name argument "is not evaluated at the point of function application, but instead is evaluated at each use within the function".
>
> But 6.12.3 offers:
> "If op is right- associative, the same operation is interpreted as { val x=e1; e2.op(x ) }, where x is a fresh name."
Diffstat (limited to 'test/files/neg/t1980.scala')
-rw-r--r-- | test/files/neg/t1980.scala | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/test/files/neg/t1980.scala b/test/files/neg/t1980.scala new file mode 100644 index 0000000000..132865e694 --- /dev/null +++ b/test/files/neg/t1980.scala @@ -0,0 +1,9 @@ +object Test { + def op1_:(x: => Any) = () // warn + def op2_:(x: Any, y: => Any) = () // warn + def op3_:(x: Any, y: => Any)(a: Any) = () // warn + + def op4() = () // no warn + def op5(x: => Any) = () // no warn + def op6_:(x: Any)(a: => Any) = () // no warn +} |