diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index 7c678f8b0094..8eda55e42272 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -884,7 +884,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => * will return a term tree. */ def unapply(tree: tpd.Apply)(using Context): Option[tpd.Tree] = - if tree.symbol.isSplice then Some(tree.args.head) else None + if tree.symbol.isExprSplice then Some(tree.args.head) else None } /** Extractors for type splices */ @@ -894,7 +894,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => * will return a type tree. */ def unapply(tree: tpd.Select)(using Context): Option[tpd.Tree] = - if tree.symbol.isSplice then Some(tree.qualifier) else None + if tree.symbol.isTypeSplice then Some(tree.qualifier) else None } /** Extractor for not-null assertions. diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 7fafb72c5e24..c724127ba3f7 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -369,7 +369,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { else if (name.isTypeName) typeText(txt) else txt case tree @ Select(qual, name) => - if (!printDebug && tree.hasType && tree.symbol == defn.QuotedType_splice) typeText("${") ~ toTextLocal(qual) ~ typeText("}") + if (!printDebug && tree.hasType && tree.symbol.isTypeSplice) typeText("${") ~ toTextLocal(qual) ~ typeText("}") else if (qual.isType) toTextLocal(qual) ~ "#" ~ typeText(toText(name)) else toTextLocal(qual) ~ ("." ~ nameIdText(tree) provided (name != nme.CONSTRUCTOR || printDebug)) case tree: This => @@ -383,7 +383,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { } else if (!printDebug && fun.hasType && fun.symbol == defn.InternalQuoted_exprQuote) keywordStr("'{") ~ toTextGlobal(args, ", ") ~ keywordStr("}") - else if (!printDebug && fun.hasType && (fun.symbol == defn.InternalQuoted_exprSplice || fun.symbol == defn.InternalQuoted_exprNestedSplice)) + else if (!printDebug && fun.hasType && fun.symbol.isExprSplice) keywordStr("${") ~ toTextGlobal(args, ", ") ~ keywordStr("}") else toTextLocal(fun) diff --git a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala index d371454acc8a..37861a0cb831 100644 --- a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala +++ b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala @@ -179,7 +179,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages( tryHeal(tp.symbol, tp, pos) case prefix: ThisType if !tp.symbol.isStatic && level > levelOf(prefix.cls) => tryHeal(tp.symbol, tp, pos) - case prefix: TermRef if tp.symbol.isSplice => + case prefix: TermRef if tp.symbol.isTypeSplice => prefix.symbol.info.argInfos match case (tb: TypeBounds) :: _ => ctx.error(em"Cannot splice $tp because it is a wildcard type", pos) diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index ad8c5776bc60..a33d1763fd87 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -78,7 +78,8 @@ class ReifyQuotes extends MacroTransform { tree match { case tree: RefTree if !Inliner.inInlineMethod => assert(!tree.symbol.isQuote) - assert(!tree.symbol.isSplice) + assert(!tree.symbol.isExprSplice) + assert(!tree.symbol.isTypeSplice) case _ : TypeDef => assert(!tree.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot), s"${tree.symbol} should have been removed by PickledQuotes because it has a @quoteTypeTag") @@ -329,7 +330,7 @@ class ReifyQuotes extends MacroTransform { /** Remove references to local types that will not be defined in this quote */ def getTypeHoleType(using ctx: Context) = new TypeMap() { override def apply(tp: Type): Type = tp match - case tp: TypeRef if tp.typeSymbol.isSplice => + case tp: TypeRef if tp.typeSymbol.isTypeSplice => apply(tp.dealias) case tp @ TypeRef(pre, _) if pre == NoPrefix || pre.termSymbol.isLocal => val hiBound = tp.typeSymbol.info match diff --git a/compiler/src/dotty/tools/dotc/transform/Staging.scala b/compiler/src/dotty/tools/dotc/transform/Staging.scala index 6138ad5b42bb..3441c38c6409 100644 --- a/compiler/src/dotty/tools/dotc/transform/Staging.scala +++ b/compiler/src/dotty/tools/dotc/transform/Staging.scala @@ -64,7 +64,7 @@ class Staging extends MacroTransform { } tree.tpe match { - case tpe @ TypeRef(prefix, _) if tpe.typeSymbol eq defn.QuotedType_splice => + case tpe @ TypeRef(prefix, _) if tpe.typeSymbol.isTypeSplice => // Type splices must have a know term ref, usually to an implicit argument // This is mostly intended to catch `quoted.Type[T]#splice` types which should just be `T` assert(prefix.isInstanceOf[TermRef] || prefix.isInstanceOf[ThisType], prefix) diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index 7eb49f2e7f80..56bc53b17da6 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -208,9 +208,13 @@ class SymUtils(val self: Symbol) extends AnyVal { def isQuote(using Context): Boolean = self == defn.InternalQuoted_exprQuote || self == defn.InternalQuoted_typeQuote - /** Is symbol a splice operation? */ - def isSplice(using Context): Boolean = - self == defn.InternalQuoted_exprSplice || self == defn.InternalQuoted_exprNestedSplice || self == defn.QuotedType_splice + /** Is symbol a term splice operation? */ + def isExprSplice(using Context): Boolean = + self == defn.InternalQuoted_exprSplice || self == defn.InternalQuoted_exprNestedSplice + + /** Is symbol a type splice operation? */ + def isTypeSplice(using Context): Boolean = + self == defn.QuotedType_splice /** Is symbol an extension method? Accessors are excluded since * after the getters phase collective extension objects become accessors diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 137946f5d133..63ebd7b28aa6 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -1208,8 +1208,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { } private def checkStaging(tree: Tree): tree.type = - val sym = tree.symbol - if sym == defn.InternalQuoted_exprQuote || sym == defn.InternalQuoted_typeQuote then + if tree.symbol.isQuote then ctx.compilationUnit.needsStaging = true tree diff --git a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala index b6ec34215410..d10ed78bcc5f 100644 --- a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala +++ b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala @@ -15,6 +15,7 @@ import dotty.tools.dotc.core.StdNames._ import dotty.tools.dotc.core.Symbols._ import dotty.tools.dotc.core.Types._ import dotty.tools.dotc.reporting._ +import dotty.tools.dotc.transform.SymUtils.decorateSymbol import dotty.tools.dotc.typer.Implicits._ import dotty.tools.dotc.typer.Inferencing._ import dotty.tools.dotc.typer.ProtoTypes._ @@ -232,7 +233,7 @@ trait QuotesAndSplices { val freshTypeBindingsBuff = new mutable.ListBuffer[Tree] val typePatBuf = new mutable.ListBuffer[Tree] override def transform(tree: Tree)(using Context) = tree match { - case Typed(Apply(fn, pat :: Nil), tpt) if fn.symbol == defn.InternalQuoted_exprSplice && !tpt.tpe.derivesFrom(defn.RepeatedParamClass) => + case Typed(Apply(fn, pat :: Nil), tpt) if fn.symbol.isExprSplice && !tpt.tpe.derivesFrom(defn.RepeatedParamClass) => val tpt1 = transform(tpt) // Transform type bindings val exprTpt = AppliedTypeTree(TypeTree(defn.QuotedExprClass.typeRef), tpt1 :: Nil) val newSplice = ref(defn.InternalQuoted_exprSplice).appliedToType(tpt1.tpe).appliedTo(Typed(pat, exprTpt)) @@ -245,7 +246,7 @@ trait QuotesAndSplices { val pat1 = if (patType eq patType1) pat else pat.withType(patType1) patBuf += pat1 } - case Apply(fn, pat :: Nil) if fn.symbol == defn.InternalQuoted_exprSplice => + case Apply(fn, pat :: Nil) if fn.symbol.isExprSplice => try ref(defn.InternalQuotedMatcher_patternHole.termRef).appliedToType(tree.tpe).withSpan(tree.span) finally { val patType = pat.tpe.widen @@ -253,7 +254,7 @@ trait QuotesAndSplices { val pat1 = if (patType eq patType1) pat else pat.withType(patType1) patBuf += pat1 } - case Select(pat, _) if tree.symbol == defn.QuotedType_splice => + case Select(pat, _) if tree.symbol.isTypeSplice => val sym = tree.tpe.dealias.typeSymbol if sym.exists then val tdef = TypeDef(sym.asType).withSpan(sym.span) @@ -320,7 +321,7 @@ trait QuotesAndSplices { val isFreshTypeBindings = freshTypeBindings.map(_.symbol).toSet val typeMap = new TypeMap() { def apply(tp: Type): Type = tp match { - case tp: TypeRef if tp.typeSymbol == defn.QuotedType_splice => + case tp: TypeRef if tp.typeSymbol.isTypeSplice => val tp1 = tp.dealias if (isFreshTypeBindings(tp1.typeSymbol)) tp1 else tp @@ -401,7 +402,7 @@ trait QuotesAndSplices { class ReplaceBindings extends TypeMap() { override def apply(tp: Type): Type = tp match { case tp: TypeRef => - val tp1 = if (tp.typeSymbol == defn.QuotedType_splice) tp.dealias else tp + val tp1 = if (tp.typeSymbol.isTypeSplice) tp.dealias else tp typeBindings.get(tp1.typeSymbol).fold(tp)(_.symbol.typeRef) case tp => mapOver(tp) }