diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 5f42c748bd33..6b7343913339 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -1109,8 +1109,8 @@ object desugar { case Block(Nil, expr) => expr // important for interpolated string as patterns, see i1773.scala case t => t } - - Apply(Select(Apply(Ident(nme.StringContext), strs), id), elems) + // This is a deliberate departure from scalac, where StringContext is not rooted (See #4732) + Apply(Select(Apply(scalaDot(nme.StringContext), strs), id), elems) case InfixOp(l, op, r) => if (ctx.mode is Mode.Type) AppliedTypeTree(op, l :: r :: Nil) // op[l, r] diff --git a/compiler/src/dotty/tools/dotc/transform/localopt/StringInterpolatorOpt.scala b/compiler/src/dotty/tools/dotc/transform/localopt/StringInterpolatorOpt.scala index 293096a2b6e7..f5bd2d64b319 100644 --- a/compiler/src/dotty/tools/dotc/transform/localopt/StringInterpolatorOpt.scala +++ b/compiler/src/dotty/tools/dotc/transform/localopt/StringInterpolatorOpt.scala @@ -34,10 +34,8 @@ class StringInterpolatorOpt extends MiniPhase { private object StringContextApply { def unapply(tree: Select)(implicit ctx: Context): Boolean = { - tree.symbol.eq(defn.StringContextModule_apply) && { - val qualifier = tree.qualifier - qualifier.isInstanceOf[Ident] && qualifier.symbol.eq(defn.StringContextModule) - } + tree.symbol.eq(defn.StringContextModule_apply) && + tree.qualifier.symbol.eq(defn.StringContextModule) } } diff --git a/tests/run/rooted_stringcontext.scala b/tests/run/rooted_stringcontext.scala new file mode 100644 index 000000000000..65f7a7e064fd --- /dev/null +++ b/tests/run/rooted_stringcontext.scala @@ -0,0 +1,10 @@ +object StringContext { + val i = 42 + val s = s"Answer: $i" +} + +object Test { + def main(args: Array[String]): Unit = { + assert(StringContext.s == "Answer: 42") + } +} \ No newline at end of file