summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2013-09-17 12:52:53 -0700
committerSom Snytt <som.snytt@gmail.com>2013-09-17 13:02:21 -0700
commit6ff756b7874fffe9cfe260be1b35536d48f88db2 (patch)
treea0c7bc6a1818cf6229b289a637cb2b0939763d35 /src
parent9dbc321504ad5550638d6d7c2b3cd2f98273cf74 (diff)
downloadscala-6ff756b7874fffe9cfe260be1b35536d48f88db2.tar.gz
scala-6ff756b7874fffe9cfe260be1b35536d48f88db2.tar.bz2
scala-6ff756b7874fffe9cfe260be1b35536d48f88db2.zip
SI-7848 Xlint says what looks interpolated
The motivating use case was an Expecty debug string getting flagged for `$eq`. The test case demonstrates a different bug, in which the position of the literal tree is changed when typer gets rid of the unused local, so that when the tree is re-typed in erasure, a second, spurious warning is emitted at the start of the method. Specifically, the second warning is not suppressed because of the different position.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 3ac0b398ee..80e9e16178 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -4878,17 +4878,23 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
}
tree.value match {
case Constant(s: String) =>
- def names = InterpolatorIdentRegex findAllIn s map (n => newTermName(n stripPrefix "$"))
- def suspicious = (
- (InterpolatorCodeRegex findFirstIn s).nonEmpty
- || (names exists (n => context.lookupSymbol(n, _ => true).symbol.exists))
- )
+ def names = InterpolatorIdentRegex findAllIn s map (n => TermName(n stripPrefix "$"))
+ def isSuspiciousExpr = (InterpolatorCodeRegex findFirstIn s).nonEmpty
+ //def isSuspiciousName = names exists symExists
+ def suspiciousName = names find symExists
+ def symExists(n: TermName) = context.lookupSymbol(n, _ => true).symbol.exists
val noWarn = (
isArgToImplicitNotFound
|| !(s contains ' ') // another heuristic - e.g. a string with only "$asInstanceOf"
)
- if (!noWarn && suspicious)
- unit.warning(tree.pos, "looks like an interpolated String; did you forget the interpolator?")
+ if (!noWarn) {
+ val suggest = "Did you forget the interpolator?"
+ if (isSuspiciousExpr)
+ unit.warning(tree.pos, s"That looks like an interpolated expression! $suggest")
+ else /* if (isSuspiciousName) */ suspiciousName foreach (n =>
+ unit.warning(tree.pos, s"`$$$n` looks like an interpolated identifier! $suggest")
+ )
+ }
case _ =>
}
}