From 9f2b2894ba2b45135943e943d13898aefc333cc2 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sun, 16 Jun 2013 14:47:26 -0400 Subject: SI-7584 Test and spurious warning fix for by-name closures The enclosed test case exercises by-name closures, which were the subject of the previous commit. In the process, a spurious warning was eliminated. --- src/reflect/scala/reflect/internal/TreeInfo.scala | 2 +- test/files/run/t7584.check | 6 ++++++ test/files/run/t7584.flags | 1 + test/files/run/t7584.scala | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/files/run/t7584.check create mode 100644 test/files/run/t7584.flags create mode 100644 test/files/run/t7584.scala diff --git a/src/reflect/scala/reflect/internal/TreeInfo.scala b/src/reflect/scala/reflect/internal/TreeInfo.scala index a5cf46071f..cd1f5f2e47 100644 --- a/src/reflect/scala/reflect/internal/TreeInfo.scala +++ b/src/reflect/scala/reflect/internal/TreeInfo.scala @@ -208,7 +208,7 @@ abstract class TreeInfo { } def isWarnableSymbol = { val sym = tree.symbol - (sym == null) || !(sym.isModule || sym.isLazy) || { + (sym == null) || !(sym.isModule || sym.isLazy || definitions.isByNameParamType(sym.tpe_*)) || { debuglog("'Pure' but side-effecting expression in statement position: " + tree) false } diff --git a/test/files/run/t7584.check b/test/files/run/t7584.check new file mode 100644 index 0000000000..9f53e5dde5 --- /dev/null +++ b/test/files/run/t7584.check @@ -0,0 +1,6 @@ +no calls +call A +a +call B twice +b +b diff --git a/test/files/run/t7584.flags b/test/files/run/t7584.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/files/run/t7584.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/test/files/run/t7584.scala b/test/files/run/t7584.scala new file mode 100644 index 0000000000..6d7f4f7ebb --- /dev/null +++ b/test/files/run/t7584.scala @@ -0,0 +1,14 @@ +// Test case added to show the behaviour of functions with +// by-name parameters. The evaluation behaviour was already correct. +// +// We did flush out a spurious "pure expression does nothing in statement position" +// warning, hence -Xfatal-warnings in the flags file. +object Test extends App { + def foo(f: (=> Int, => Int) => Unit) = f({println("a"); 0}, {println("b"); 1}) + println("no calls") + foo((a, b) => ()) + println("call A") + foo((a, b) => a) + println("call B twice") + foo((a, b) => {b; b}) +} -- cgit v1.2.3