summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-04-23 14:20:01 -0700
committerPaul Phillips <paulp@improving.org>2013-04-23 15:36:35 -0700
commit0f1a004048089dc2f51c5e1a11419072102b896b (patch)
tree019a1b64ad10f54f07be91bf60602457e1c1e504 /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parentd02ccc30815cb75a845b7d56ad6db8de91e442c5 (diff)
downloadscala-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.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala30
1 files changed, 22 insertions, 8 deletions
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) = {