summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2013-09-18 18:06:59 -0700
committerSom Snytt <som.snytt@gmail.com>2013-09-18 20:36:16 -0700
commita5bae8f17cb96feb75fdc81480827ce44746fd1d (patch)
treecf468c6235fdb8df18c1bffb919431b936e817d1 /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parent40d57db2998d9b2cc438bb268dc859d04b5df55c (diff)
downloadscala-a5bae8f17cb96feb75fdc81480827ce44746fd1d.tar.gz
scala-a5bae8f17cb96feb75fdc81480827ce44746fd1d.tar.bz2
scala-a5bae8f17cb96feb75fdc81480827ce44746fd1d.zip
SI-7848 Xlint no warn on $sym with params
This idea brought to you by retronym.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 88b9b2c71c..3343ee2bcc 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -4876,25 +4876,30 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
case Apply(fn, _) => 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 => 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) {
- 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")
- )
- }
+ if (!noWarn) warnAbout(s)
case _ =>
}
}