From 275305a3d291cca49163903b5b6fe1d496b507a6 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sun, 20 Mar 2016 20:10:58 -0700 Subject: 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. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') 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" } -- cgit v1.2.3