From 0709e6c433065ff5535926bd6c208f9eaedbdad4 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 14 May 2019 15:44:28 +0200 Subject: [PATCH 1/2] Avoid ambiguities between scala.StringContext and internal.StringContext --- compiler/src/dotty/tools/dotc/core/Definitions.scala | 8 ++++---- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- .../{StringContext.scala => StringContextMacro.scala} | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) rename library/src-3.x/dotty/internal/{StringContext.scala => StringContextMacro.scala} (86%) diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 8f17da8500de..e1e6a0162789 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index d0505bb5aa70..38cfa7da2d11 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -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) diff --git a/library/src-3.x/dotty/internal/StringContext.scala b/library/src-3.x/dotty/internal/StringContextMacro.scala similarity index 86% rename from library/src-3.x/dotty/internal/StringContext.scala rename to library/src-3.x/dotty/internal/StringContextMacro.scala index 04279c602c4c..e818152f79ad 100644 --- a/library/src-3.x/dotty/internal/StringContext.scala +++ b/library/src-3.x/dotty/internal/StringContextMacro.scala @@ -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 From 4bf4cb80d62409447532d812ccdd2bc08c9b0866 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 14 May 2019 15:49:42 +0200 Subject: [PATCH 2/2] Remove assertion This assertion is too strong in some we have an under-constrained expression for which the error has still not been emitted. --- compiler/src/dotty/tools/dotc/ast/tpd.scala | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 28f11a24de21..3d996a57693b 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -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 {