diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2016-11-09 14:10:59 +0100 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2016-11-09 14:42:01 +0100 |
commit | c1e9b0a951ee5298244c6456af3641ee966e101b (patch) | |
tree | f090170211e20b101d7477e9b269a7c0d10d945a /test/files/run/t10032.check | |
parent | f297ca8d1f06086316ff3746250092e36ef9f74e (diff) | |
download | scala-c1e9b0a951ee5298244c6456af3641ee966e101b.tar.gz scala-c1e9b0a951ee5298244c6456af3641ee966e101b.tar.bz2 scala-c1e9b0a951ee5298244c6456af3641ee966e101b.zip |
Fix returns from within finalizers
When a return in a finalizer was reached through a return within the try
block, the backend ignored the return in the finalizer:
try {
try { return 1 }
finally { return 2 }
} finally { println() }
This expression should evaluate to 2 (it does in 2.11.8), but in 2.12.0
it the result is 1.
The Scala spec is currently incomplete, it does not say that a finalizer
should be exectuted if a return occurs within a try block, and it does
not specify what happens if also the finally block has a return.
So we follow the Java spec, which basically says: if the finally blocks
completes abruptly for reason S, then the entire try statement completes
abruptly with reason S. An abrupt termination of the try block for a
different reason R is discarded.
Abrupt completion is basically returning or throwing.
Diffstat (limited to 'test/files/run/t10032.check')
-rw-r--r-- | test/files/run/t10032.check | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/test/files/run/t10032.check b/test/files/run/t10032.check index c8f0bdf034..565fe25848 100644 --- a/test/files/run/t10032.check +++ b/test/files/run/t10032.check @@ -1,6 +1,3 @@ -t10032.scala:72: warning: Return statement found in finally-clause, discarding its return-value in favor of that of a more deeply nested return. - finally { return i2 } - ^ t1 i1 a1 @@ -22,6 +19,9 @@ t3 t4 i1 i2 +t4 + e1 + i2 t5 i1 a1 @@ -35,6 +35,10 @@ t6 i1 i2 i3 +t6 + e1 + i2 + i3 t7 i1 a1 @@ -47,3 +51,32 @@ t8 i2 a1 a2 +t8 + e1 + i2 + a1 + a2 +t9 + i1 + i2 + a1 +t9 + e1 + i2 + a1 +t10 + i1 + i2 + i3 +t10 + e1 + i2 + i3 +t11 + i1 + i2 + a1 +t11 + e1 + i2 + a1 |