diff options
author | Martin Odersky <odersky@gmail.com> | 2016-09-17 22:32:10 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-09-17 22:33:14 +0200 |
commit | 528f6b0524c465a3e795aa5bb538c680956bf6d2 (patch) | |
tree | 2a0f48e7f1ea2c9a52c15d0c9038712173804d41 /tests | |
parent | c420b4cc0573e88bf301d4e020e2ad91b26806d0 (diff) | |
download | dotty-528f6b0524c465a3e795aa5bb538c680956bf6d2.tar.gz dotty-528f6b0524c465a3e795aa5bb538c680956bf6d2.tar.bz2 dotty-528f6b0524c465a3e795aa5bb538c680956bf6d2.zip |
Fix #1503 - be careful where to insert an apply.
`apply` nodes should not be inserted in the result parts
of a block, if-then-else, match, or try. Instead they should
be added to the surrounding statement.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/neg/i1503.scala | 14 | ||||
-rw-r--r-- | tests/run/i1503.check | 5 | ||||
-rw-r--r-- | tests/run/i1503.scala | 38 |
3 files changed, 57 insertions, 0 deletions
diff --git a/tests/neg/i1503.scala b/tests/neg/i1503.scala new file mode 100644 index 000000000..8e5dc53c6 --- /dev/null +++ b/tests/neg/i1503.scala @@ -0,0 +1,14 @@ +object Test { + + val cond = true + def foo1() = println("hi") + def bar1() = println("there") + + def foo2(x: Int) = println("hi") + def bar2(x: Int) = println("there") + + def main(args: Array[String]) = { + (if (cond) foo1 else bar1)() // error: Unit does not take parameters + (if (cond) foo2 else bar2)(22) // error: missing arguments // error: missing arguments + } +} diff --git a/tests/run/i1503.check b/tests/run/i1503.check new file mode 100644 index 000000000..8cc0be027 --- /dev/null +++ b/tests/run/i1503.check @@ -0,0 +1,5 @@ +hello +hi +33 +hi +hi diff --git a/tests/run/i1503.scala b/tests/run/i1503.scala new file mode 100644 index 000000000..56bb9af0c --- /dev/null +++ b/tests/run/i1503.scala @@ -0,0 +1,38 @@ +object Test { + + def test1() = + (new Function0[Unit] { + def apply() = println("hello") + })() + + val cond = true + val foo = () => println("hi") + val bar = () => println("there") + + val baz = (x: Int) => println(x) + + def test2() = + (if (cond) foo else bar)() + + def test2a() = + (if (cond) baz else baz)(33) + + def test3() = + (try foo + catch { case ex: Exception => bar } + finally ())() + + def test4() = + (cond match { + case true => foo + case false => bar + })() + + def main(args: Array[String]) = { + test1() + test2() + test2a() + test3() + test4() + } +} |