Skip to content

Commit 89412a0

Browse files
committed
Mode internal StringContext.f implementation to dotty package
1 parent 4b8f227 commit 89412a0

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ class Definitions {
637637
lazy val StringContextModule_applyR: TermRef = StringContextModule.requiredMethodRef(nme.apply)
638638
def StringContextModule_apply(implicit ctx: Context): Symbol = StringContextModule_applyR.symbol
639639

640-
lazy val InternalStringContextModuleR: TermRef = ctx.requiredModuleRef("scala.internal.StringContext")
640+
lazy val InternalStringContextModuleR: TermRef = ctx.requiredModuleRef("dotty.internal.StringContext")
641641
def InternalStringContextModule(implicit ctx: Context): Symbol = InternalStringContextModuleR.termSymbol
642642
lazy val InternalStringContextModule_fR: TermRef = InternalStringContextModule.requiredMethodRef(nme.f)
643643
def InternalStringContextModule_f(implicit ctx: Context): Symbol = InternalStringContextModule_fR.symbol

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2755,9 +2755,14 @@ class Typer extends Namer
27552755
}
27562756
else if (tree.symbol.isScala2Macro) {
27572757
if (ctx.settings.XignoreScala2Macros.value) {
2758-
ctx.warning("Scala 2 macro cannot be used in Dotty. See http://dotty.epfl.ch/docs/reference/dropped-features/macros.html", tree.sourcePos)
2758+
ctx.warning("Scala 2 macro cannot be used in Dotty, this call will crash at runtime. See http://dotty.epfl.ch/docs/reference/dropped-features/macros.html", tree.sourcePos)
27592759
tree
27602760
} else if (tree.symbol eq defn.StringContext_f) {
2761+
// As scala.StringContext.f is defined in the standard library which
2762+
// we currently do not bootstrap we cannot implement the macro the library.
2763+
// To overcome the current limitation we intercept the call and rewrite it into
2764+
// a call to dotty.internal.StringContext.f which we can implement using the new macros.
2765+
// As the macro is implemented in the bootstrapped library, it can only be used from the bootstrapped compiler.
27612766
val Apply(TypeApply(Select(sc, _), _), args) = tree
27622767
val newCall = ref(defn.InternalStringContextModule_f).appliedTo(sc).appliedToArgs(args)
27632768
Inliner.inlineCall(newCall, pt)

library/src-bootstrapped/scala/internal/StringContext.scala renamed to library/src-bootstrapped/dotty/internal/StringContext.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
package scala.internal
1+
package dotty.internal
22

33
import scala.quoted._
44

55
object StringContext {
66

7+
/** Implemetation of scala.StringContext.f used in Dotty while the standard library is still not bootstrapped */
78
inline def f(sc: => scala.StringContext)(args: Any*): String = ${ fImpl('sc, 'args) }
89

910
private def fImpl(sc: Expr[StringContext], args: Expr[Seq[Any]]): Expr[String] = {

library/src-non-bootstrapped/scala/internal/StringContext.scala renamed to library/src-non-bootstrapped/dotty/internal/StringContext.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package scala.internal
1+
package dotty.internal
22

33
object StringContext {
44

0 commit comments

Comments
 (0)