summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2016-03-20 20:10:58 -0700
committerSom Snytt <som.snytt@gmail.com>2016-03-20 20:10:58 -0700
commit275305a3d291cca49163903b5b6fe1d496b507a6 (patch)
treebb9bd78af4b96e4864cd540ad543748a653296bc /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parent416326ebeaffef29cda3522ea828950e45cedcc0 (diff)
downloadscala-275305a3d291cca49163903b5b6fe1d496b507a6.tar.gz
scala-275305a3d291cca49163903b5b6fe1d496b507a6.tar.bz2
scala-275305a3d291cca49163903b5b6fe1d496b507a6.zip
SI-9314 Ignore "${}"
As an Easter egg, let "${} $x" forego the check on `x`. In other words, empty expression interpolation looks too degenerate to check.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 3f0d0e655d..1b55618691 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -105,7 +105,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
// that are turned private by typedBlock
private final val SYNTHETIC_PRIVATE = TRANS_FLAG
- private final val InterpolatorCodeRegex = """\$\{.*?\}""".r
+ private final val InterpolatorCodeRegex = """\$\{(.*?)\}""".r
private final val InterpolatorIdentRegex = """\$[$\w]+""".r // note that \w doesn't include $
abstract class Typer(context0: Context) extends TyperDiagnostics with Adaptation with Tag with PatternTyper with TyperContextErrors {
@@ -5211,11 +5211,13 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
def maybeWarn(s: String): Unit = {
def warn(message: String) = context.warning(lit.pos, s"possible missing interpolator: $message")
def suspiciousSym(name: TermName) = context.lookupSymbol(name, _ => true).symbol
- def suspiciousExpr = InterpolatorCodeRegex findFirstIn s
+ val suspiciousExpr = InterpolatorCodeRegex findFirstMatchIn s
def suspiciousIdents = InterpolatorIdentRegex findAllIn s map (s => suspiciousSym(TermName(s drop 1)))
if (suspiciousExpr.nonEmpty)
- warn("detected an interpolated expression") // "${...}"
+ suspiciousExpr filter (!_.group(1).trim.isEmpty) foreach (_ =>
+ warn("detected an interpolated expression") // "${...}"
+ )
else
suspiciousIdents find isPlausible foreach (sym => warn(s"detected interpolated identifier `$$${sym.name}`")) // "$id"
}