Skip to content

Avoid ambiguities between scala.StringContext and internal.StringContext #6509

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
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
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1184,10 +1184,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
val baseType = tree.tpe.baseType(defn.QuotedExprClass)
val argType =
if (baseType != NoType) baseType.argTypesHi.head
else {
assert(ctx.reporter.hasErrors)
defn.NothingType
}
else defn.NothingType
ref(defn.InternalQuoted_exprSplice).appliedToType(argType).appliedTo(tree)
}
def unapply(tree: Tree)(implicit ctx: Context): Option[Tree] = tree match {
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,10 @@ class Definitions {
lazy val StringContextModule_applyR: TermRef = StringContextModule.requiredMethodRef(nme.apply)
def StringContextModule_apply(implicit ctx: Context): Symbol = StringContextModule_applyR.symbol

lazy val InternalStringContextModuleR: TermRef = ctx.requiredModuleRef("dotty.internal.StringContext")
def InternalStringContextModule(implicit ctx: Context): Symbol = InternalStringContextModuleR.termSymbol
lazy val InternalStringContextModule_fR: TermRef = InternalStringContextModule.requiredMethodRef(nme.f)
def InternalStringContextModule_f(implicit ctx: Context): Symbol = InternalStringContextModule_fR.symbol
lazy val InternalStringContextMacroModuleR: TermRef = ctx.requiredModuleRef("dotty.internal.StringContextMacro")
def InternalStringContextMacroModule(implicit ctx: Context): Symbol = InternalStringContextMacroModuleR.termSymbol
lazy val InternalStringContextMacroModule_fR: TermRef = InternalStringContextMacroModule.requiredMethodRef(nme.f)
def InternalStringContextMacroModule_f(implicit ctx: Context): Symbol = InternalStringContextMacroModule_fR.symbol

lazy val PartialFunctionType: TypeRef = ctx.requiredClassRef("scala.PartialFunction")
def PartialFunctionClass(implicit ctx: Context): ClassSymbol = PartialFunctionType.symbol.asClass
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2784,7 +2784,7 @@ class Typer extends Namer
// a call to dotty.internal.StringContext.f which we can implement using the new macros.
// As the macro is implemented in the bootstrapped library, it can only be used from the bootstrapped compiler.
val Apply(TypeApply(Select(sc, _), _), args) = tree
val newCall = ref(defn.InternalStringContextModule_f).appliedTo(sc).appliedToArgs(args)
val newCall = ref(defn.InternalStringContextMacroModule_f).appliedTo(sc).appliedToArgs(args)
readaptSimplified(Inliner.inlineCall(newCall))
} else {
ctx.error("Scala 2 macro cannot be used in Dotty. See http://dotty.epfl.ch/docs/reference/dropped-features/macros.html", tree.sourcePos)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package dotty.internal

import scala.quoted._

object StringContext {
object StringContextMacro {

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

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