diff options
author | Paul Phillips <paulp@improving.org> | 2013-04-23 14:20:01 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-04-23 15:36:35 -0700 |
commit | 0f1a004048089dc2f51c5e1a11419072102b896b (patch) | |
tree | 019a1b64ad10f54f07be91bf60602457e1c1e504 | |
parent | d02ccc30815cb75a845b7d56ad6db8de91e442c5 (diff) | |
download | scala-0f1a004048089dc2f51c5e1a11419072102b896b.tar.gz scala-0f1a004048089dc2f51c5e1a11419072102b896b.tar.bz2 scala-0f1a004048089dc2f51c5e1a11419072102b896b.zip |
Taught -Xlint about @implicitNotFound.
And also about what a compiler identifier with a $ is likely
to look like. So it can stop burying me in warnings about missing
String interpolators which aren't so missing.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Contexts.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 30 |
2 files changed, 23 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 949cd13520..cccaac6426 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -178,6 +178,7 @@ trait Contexts { self: Analyzer => if ((owner eq NoSymbol) || (owner.isClass) || (owner.isMethod)) this else outer.enclClassOrMethod + def enclosingApply = nextEnclosing(_.tree.isInstanceOf[Apply]) def enclosingCaseDef = nextEnclosing(_.tree.isInstanceOf[CaseDef]) def undetparamsString = if (undetparams.isEmpty) "" diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 60b6248a07..02ab456046 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -5100,24 +5100,38 @@ trait Typers extends Adaptations with Tags { treeCopy.ReferenceToBoxed(tree, id1) setType tpe } - def typedLiteral(tree: Literal) = { - val value = tree.value - // Warn about likely interpolated strings which are missing their interpolators - if (settings.lint) value match { + // Warn about likely interpolated strings which are missing their interpolators + def warnMissingInterpolator(tree: Literal) { + // Unfortunately implicit not found strings looks for all the world like + // missing interpolators. + def isArgToImplicitNotFound = context.enclosingApply.tree match { + case Apply(fn, _) => fn.symbol.enclClass == ImplicitNotFoundClass + case _ => false + } + tree.value match { case Constant(s: String) => def names = InterpolatorIdentRegex findAllIn s map (n => newTermName(n stripPrefix "$")) - val shouldWarn = ( + def suspicious = ( (InterpolatorCodeRegex findFirstIn s).nonEmpty || (names exists (n => context.lookupSymbol(n, _ => true).symbol.exists)) ) - if (shouldWarn) + 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?") case _ => } + } + + def typedLiteral(tree: Literal) = { + if (settings.lint) + warnMissingInterpolator(tree) tree setType ( - if (value.tag == UnitTag) UnitClass.tpe - else ConstantType(value)) + if (tree.value.tag == UnitTag) UnitClass.tpe + else ConstantType(tree.value)) } def typedSingletonTypeTree(tree: SingletonTypeTree) = { |