summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-09-23 05:22:50 -0700
committerJason Zaugg <jzaugg@gmail.com>2013-09-23 05:22:50 -0700
commitc3ec1c2ac45d9fb261d40fd1baefc2f6d965ac36 (patch)
treefbf498f26b6f4945663c6955fd9a1fb771026f20 /src
parent6f6d102a83f1b890f4061082b4b1ec5733c8dde2 (diff)
parenta5bae8f17cb96feb75fdc81480827ce44746fd1d (diff)
downloadscala-c3ec1c2ac45d9fb261d40fd1baefc2f6d965ac36.tar.gz
scala-c3ec1c2ac45d9fb261d40fd1baefc2f6d965ac36.tar.bz2
scala-c3ec1c2ac45d9fb261d40fd1baefc2f6d965ac36.zip
Merge pull request #2956 from som-snytt/issue/7848-forgotten-interp-msg
SI-7848 Xlint says what looks interpolated
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index e07c68de8a..157c6ba4de 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -4874,26 +4874,37 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
}
// Warn about likely interpolated strings which are missing their interpolators
- def warnMissingInterpolator(tree: Literal) {
+ def warnMissingInterpolator(tree: Literal) = if (!isPastTyper) {
// Unfortunately implicit not found strings looks for all the world like
// missing interpolators.
def isArgToImplicitNotFound = context.enclosingApply.tree match {
case Apply(fn, _) => fn.symbol != null && fn.symbol.enclClass == ImplicitNotFoundClass
case _ => false
}
+ def warnAbout(s: String) = {
+ def names = InterpolatorIdentRegex findAllIn s map (n => TermName(n stripPrefix "$"))
+ def isSuspiciousExpr = (InterpolatorCodeRegex findFirstIn s).nonEmpty
+ //def isSuspiciousName = names exists (lookUp _ andThen (_.exists))
+ def suspiciousName = names find (lookUp _ andThen (_.exists))
+ def lookUp(n: TermName) = context.lookupSymbol(n, !_.alternatives.exists(symRequiresArg)).symbol
+ def symRequiresArg(s: Symbol) = (
+ s.paramss.nonEmpty
+ && (s.paramss.head.headOption filterNot (_.isImplicit)).isDefined
+ )
+ 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")
+ )
+ }
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))
- )
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) warnAbout(s)
case _ =>
}
}