diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 8 | ||||
-rw-r--r-- | test/files/neg/t7848-interp-warn.scala | 2 |
2 files changed, 7 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" } diff --git a/test/files/neg/t7848-interp-warn.scala b/test/files/neg/t7848-interp-warn.scala index 6a289b2b71..635dd48c27 100644 --- a/test/files/neg/t7848-interp-warn.scala +++ b/test/files/neg/t7848-interp-warn.scala @@ -25,4 +25,6 @@ object Test { def i = s"Try using '${ "$bar" }' instead." // was: no warn on space test def j = s"Try using '${ "something like $bar" }' instead." // warn def k = f"Try using '$bar' instead." // no warn on other std interps + def p = "Template ${} {}" // no warn on unlikely or empty expressions + def q = "${}$bar" // disables subsequent checks! } |