From 9fed30cb9c6d86ca07286febeb44bf635cb23650 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 11 Mar 2013 22:11:19 -0700 Subject: Warn about forgotten string interpolators. In the compiler sources this arrives with a number of false positives, because we frequently work with strings containing $foo where foo is an in-scope identifier. I think in normal source code this will be less of a problem, or none at all; but to be conservative the warning is born under -Xlint. --- test/files/neg/forgot-interpolator.check | 9 +++++++++ test/files/neg/forgot-interpolator.flags | 1 + test/files/neg/forgot-interpolator.scala | 15 +++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 test/files/neg/forgot-interpolator.check create mode 100644 test/files/neg/forgot-interpolator.flags create mode 100644 test/files/neg/forgot-interpolator.scala (limited to 'test/files/neg') diff --git a/test/files/neg/forgot-interpolator.check b/test/files/neg/forgot-interpolator.check new file mode 100644 index 0000000000..f6de4d7b3a --- /dev/null +++ b/test/files/neg/forgot-interpolator.check @@ -0,0 +1,9 @@ +forgot-interpolator.scala:4: warning: looks like an interpolated String; did you forget the interpolator? + def f = "Put the $bippy in the $bippy!" // warn + ^ +forgot-interpolator.scala:14: warning: looks like an interpolated String; did you forget the interpolator? + def f = """Put the ${println("bippy")} in the bippy!""" // warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/test/files/neg/forgot-interpolator.flags b/test/files/neg/forgot-interpolator.flags new file mode 100644 index 0000000000..7949c2afa2 --- /dev/null +++ b/test/files/neg/forgot-interpolator.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings diff --git a/test/files/neg/forgot-interpolator.scala b/test/files/neg/forgot-interpolator.scala new file mode 100644 index 0000000000..d67db82643 --- /dev/null +++ b/test/files/neg/forgot-interpolator.scala @@ -0,0 +1,15 @@ +class A { + val bippy = 123 + + def f = "Put the $bippy in the $bippy!" // warn +} + +class B { + val dingus = 123 + + def f = "Put the $bippy in the $bippy!" // no warn +} + +class C { + def f = """Put the ${println("bippy")} in the bippy!""" // warn +} -- cgit v1.2.3