Skip to content

Commit 72574cf

Browse files
Merge pull request #6509 from dotty-staging/avoid-StringContext-ambiguities
Avoid ambiguities between scala.StringContext and internal.StringContext
2 parents 3ef991d + 4bf4cb8 commit 72574cf

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,10 +1184,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11841184
val baseType = tree.tpe.baseType(defn.QuotedExprClass)
11851185
val argType =
11861186
if (baseType != NoType) baseType.argTypesHi.head
1187-
else {
1188-
assert(ctx.reporter.hasErrors)
1189-
defn.NothingType
1190-
}
1187+
else defn.NothingType
11911188
ref(defn.InternalQuoted_exprSplice).appliedToType(argType).appliedTo(tree)
11921189
}
11931190
def unapply(tree: Tree)(implicit ctx: Context): Option[Tree] = tree match {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,10 @@ 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("dotty.internal.StringContext")
641-
def InternalStringContextModule(implicit ctx: Context): Symbol = InternalStringContextModuleR.termSymbol
642-
lazy val InternalStringContextModule_fR: TermRef = InternalStringContextModule.requiredMethodRef(nme.f)
643-
def InternalStringContextModule_f(implicit ctx: Context): Symbol = InternalStringContextModule_fR.symbol
640+
lazy val InternalStringContextMacroModuleR: TermRef = ctx.requiredModuleRef("dotty.internal.StringContextMacro")
641+
def InternalStringContextMacroModule(implicit ctx: Context): Symbol = InternalStringContextMacroModuleR.termSymbol
642+
lazy val InternalStringContextMacroModule_fR: TermRef = InternalStringContextMacroModule.requiredMethodRef(nme.f)
643+
def InternalStringContextMacroModule_f(implicit ctx: Context): Symbol = InternalStringContextMacroModule_fR.symbol
644644

645645
lazy val PartialFunctionType: TypeRef = ctx.requiredClassRef("scala.PartialFunction")
646646
def PartialFunctionClass(implicit ctx: Context): ClassSymbol = PartialFunctionType.symbol.asClass

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2784,7 +2784,7 @@ class Typer extends Namer
27842784
// a call to dotty.internal.StringContext.f which we can implement using the new macros.
27852785
// As the macro is implemented in the bootstrapped library, it can only be used from the bootstrapped compiler.
27862786
val Apply(TypeApply(Select(sc, _), _), args) = tree
2787-
val newCall = ref(defn.InternalStringContextModule_f).appliedTo(sc).appliedToArgs(args)
2787+
val newCall = ref(defn.InternalStringContextMacroModule_f).appliedTo(sc).appliedToArgs(args)
27882788
readaptSimplified(Inliner.inlineCall(newCall))
27892789
} else {
27902790
ctx.error("Scala 2 macro cannot be used in Dotty. See http://dotty.epfl.ch/docs/reference/dropped-features/macros.html", tree.sourcePos)

library/src-3.x/dotty/internal/StringContext.scala renamed to library/src-3.x/dotty/internal/StringContextMacro.scala

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

33
import scala.quoted._
44

5-
object StringContext {
5+
object StringContextMacro {
66

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

1010
private def fImpl(sc: Expr[StringContext], args: Expr[Seq[Any]]): Expr[String] = {
1111
// TODO implement f interpolation checks and generate optimal code

0 commit comments

Comments
 (0)