diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2012-12-10 12:19:43 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2012-12-10 12:19:43 -0800 |
commit | 84eff4d144e1523f1a51ffca77eb983a29eccd72 (patch) | |
tree | 09f26a6add77fa574a53c95b6814e62fd8a6bbc7 /test/files | |
parent | 6f121da8902ea0b7a778f1ae1e690490330ba2ca (diff) | |
parent | 8434922d6f0ead95a2109a5e41f4db4136449e93 (diff) | |
download | scala-84eff4d144e1523f1a51ffca77eb983a29eccd72.tar.gz scala-84eff4d144e1523f1a51ffca77eb983a29eccd72.tar.bz2 scala-84eff4d144e1523f1a51ffca77eb983a29eccd72.zip |
Merge pull request #1711 from retronym/ticket/1672
SI-1672 Catches are in tail position without finally.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/neg/t1672b.check | 16 | ||||
-rw-r--r-- | test/files/neg/t1672b.scala | 52 | ||||
-rw-r--r-- | test/files/pos/t1672.scala | 10 | ||||
-rw-r--r-- | test/files/run/t1672.scala | 28 |
4 files changed, 106 insertions, 0 deletions
diff --git a/test/files/neg/t1672b.check b/test/files/neg/t1672b.check new file mode 100644 index 0000000000..60ccf77174 --- /dev/null +++ b/test/files/neg/t1672b.check @@ -0,0 +1,16 @@ +t1672b.scala:3: error: could not optimize @tailrec annotated method bar: it contains a recursive call not in tail position + def bar : Nothing = { + ^ +t1672b.scala:14: error: could not optimize @tailrec annotated method baz: it contains a recursive call not in tail position + def baz : Nothing = { + ^ +t1672b.scala:29: error: could not optimize @tailrec annotated method boz: it contains a recursive call not in tail position + case _: Throwable => boz; ??? + ^ +t1672b.scala:34: error: could not optimize @tailrec annotated method bez: it contains a recursive call not in tail position + def bez : Nothing = { + ^ +t1672b.scala:46: error: could not optimize @tailrec annotated method bar: it contains a recursive call not in tail position + else 1 + (try { + ^ +5 errors found diff --git a/test/files/neg/t1672b.scala b/test/files/neg/t1672b.scala new file mode 100644 index 0000000000..0ccdd03633 --- /dev/null +++ b/test/files/neg/t1672b.scala @@ -0,0 +1,52 @@ +object Test { + @annotation.tailrec + def bar : Nothing = { + try { + throw new RuntimeException + } catch { + case _: Throwable => bar + } finally { + bar + } + } + + @annotation.tailrec + def baz : Nothing = { + try { + throw new RuntimeException + } catch { + case _: Throwable => baz + } finally { + ??? + } + } + + @annotation.tailrec + def boz : Nothing = { + try { + throw new RuntimeException + } catch { + case _: Throwable => boz; ??? + } + } + + @annotation.tailrec + def bez : Nothing = { + try { + bez + } finally { + ??? + } + } + + // the `liftedTree` local method will prevent a tail call here. + @annotation.tailrec + def bar(i : Int) : Int = { + if (i == 0) 0 + else 1 + (try { + throw new RuntimeException + } catch { + case _: Throwable => bar(i - 1) + }) + } +} diff --git a/test/files/pos/t1672.scala b/test/files/pos/t1672.scala new file mode 100644 index 0000000000..5ee6bb1759 --- /dev/null +++ b/test/files/pos/t1672.scala @@ -0,0 +1,10 @@ +object Test { + @annotation.tailrec + def bar : Nothing = { + try { + throw new RuntimeException + } catch { + case _: Throwable => bar + } + } +} diff --git a/test/files/run/t1672.scala b/test/files/run/t1672.scala new file mode 100644 index 0000000000..ee025b9031 --- /dev/null +++ b/test/files/run/t1672.scala @@ -0,0 +1,28 @@ +object Test { + @annotation.tailrec + def bar(i : Int) : Int = { + if (i == 0) 0 + else try { + throw new RuntimeException + } catch { + case _: Throwable => bar(i - 1) + } + } + + @annotation.tailrec + def nestedTry1(i : Int) : Int = { + if (i == 0) 0 + else try { + throw new RuntimeException + } catch { + case _: Throwable => + try { ??? } catch { case _: Throwable => nestedTry1(i - 1) } + } + } + + def main(args: Array[String]) { + assert(bar(2) == 0) + + assert(nestedTry1(2) == 0) + } +} |