From 0bcb9e9169146e3f589c6c9f65cc4a5523b78120 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sat, 3 Nov 2012 16:19:46 +0100 Subject: SI-6567 Warning for Option(implicitView(foo)) I've seen the reported problem before in the wild. It seems worthy of a special warning, so long as we advocate Option.apply as an alternative to `if (x == null) Some(x) else None`. It is behind -Xlint at the moment, an option that could do with some promotion. --- test/files/neg/t6567.check | 9 +++++++++ test/files/neg/t6567.flags | 1 + test/files/neg/t6567.scala | 11 +++++++++++ 3 files changed, 21 insertions(+) create mode 100644 test/files/neg/t6567.check create mode 100644 test/files/neg/t6567.flags create mode 100644 test/files/neg/t6567.scala (limited to 'test') diff --git a/test/files/neg/t6567.check b/test/files/neg/t6567.check new file mode 100644 index 0000000000..a733d75354 --- /dev/null +++ b/test/files/neg/t6567.check @@ -0,0 +1,9 @@ +t6567.scala:8: warning: Suspicious application of an implicit view (Test.this.a2b) in the argument to Option.apply. + Option[B](a) + ^ +t6567.scala:10: warning: Suspicious application of an implicit view (Test.this.a2b) in the argument to Option.apply. + val b: Option[B] = Option(a) + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/test/files/neg/t6567.flags b/test/files/neg/t6567.flags new file mode 100644 index 0000000000..e93641e931 --- /dev/null +++ b/test/files/neg/t6567.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings \ No newline at end of file diff --git a/test/files/neg/t6567.scala b/test/files/neg/t6567.scala new file mode 100644 index 0000000000..650e5e39ae --- /dev/null +++ b/test/files/neg/t6567.scala @@ -0,0 +1,11 @@ +class A +class B + +object Test { + val a: A = null + implicit def a2b(a: A) = new B + + Option[B](a) + + val b: Option[B] = Option(a) +} -- cgit v1.2.3