Skip to content

Fix #4732: Root the desugared call to StringContext #4779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
10 changes: 10 additions & 0 deletions tests/run/rooted_stringcontext.scala
Original file line number Diff line number Diff line change
@@ -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")
}
}