From edff735a9cfd2f70e1477b2995c6e2bbf48dc91a Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 29 Sep 2020 20:58:29 +0200 Subject: [PATCH] Rework Reflect Constant The current definition of Constant.unapply is unsound because there is no way to tests if the constant contains a `Type`. We added `Constant.ClassTag.unapply` to work around this limitation, but the original was still unsound. That definition has it's own design flaws. To properly match all constants we provide an extractor for each kind of constant. This has the added advantage of being able to scale if new constants are added later. We also rename `Constant.ClassTag` to `ClassOf` as it represent a `classOf[T]`. --- community-build/community-projects/scalatest | 2 +- community-build/community-projects/shapeless | 2 +- community-build/community-projects/upickle | 2 +- community-build/community-projects/utest | 2 +- .../tools/dotc/quoted/QuoteContextImpl.scala | 89 ++++++++++- .../scala/internal/quoted/Expr.scala | 4 +- .../scala/quoted/Liftable.scala | 58 ++++++-- library/src/scala/tasty/Reflection.scala | 139 ++++++++++++++++-- .../tasty/reflect/ExtractorsPrinter.scala | 26 ++-- .../tasty/reflect/SourceCodePrinter.scala | 32 ++-- .../tasty-constant-type/Macro_1.scala | 6 +- tests/pos-macros/treemap-unapply/Macro.scala | 2 +- .../Yretain-trees/tasty-definitions-2.check | 4 +- .../Yretain-trees/tasty-load-tree-1.check | 4 +- .../f-interpolation-1/FQuote_1.scala | 2 +- tests/run-macros/i5119.check | 4 +- tests/run-macros/i5119b.check | 8 +- tests/run-macros/i6988/FirstArg_1.scala | 2 +- tests/run-macros/i9812b/Macro_1.scala | 2 +- .../refined-selectable-macro/Macro_1.scala | 2 +- tests/run-macros/tasty-argument-tree-1.check | 22 +-- .../tasty-construct-types/Macro_1.scala | 8 +- .../tasty-create-method-symbol/Macro_1.scala | 16 +- tests/run-macros/tasty-eval/quoted_1.scala | 4 +- tests/run-macros/tasty-extractors-1.check | 100 ++++++------- tests/run-macros/tasty-extractors-2.check | 64 ++++---- .../tasty-indexed-map/quoted_1.scala | 2 +- .../tasty-interpolation-1/Macro.scala | 2 +- .../tasty-macro-const/quoted_1.scala | 2 +- .../xml-interpolation-1/XmlQuote_1.scala | 2 +- .../xml-interpolation-2/XmlQuote_1.scala | 2 +- 31 files changed, 419 insertions(+), 197 deletions(-) diff --git a/community-build/community-projects/scalatest b/community-build/community-projects/scalatest index 4343430fd376..e447cc132f61 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit 4343430fd376ea3169cc3f052f560afe109747ba +Subproject commit e447cc132f61444ec97e50d9937a85b10c0d76e2 diff --git a/community-build/community-projects/shapeless b/community-build/community-projects/shapeless index 2bdebb6da59f..9f6cb180bdab 160000 --- a/community-build/community-projects/shapeless +++ b/community-build/community-projects/shapeless @@ -1 +1 @@ -Subproject commit 2bdebb6da59fafd55ecbbd13d0550b92df4d9a3d +Subproject commit 9f6cb180bdabc09886c2665ed17ed8bc1ea77afd diff --git a/community-build/community-projects/upickle b/community-build/community-projects/upickle index e8f0568acb73..47e602e405f1 160000 --- a/community-build/community-projects/upickle +++ b/community-build/community-projects/upickle @@ -1 +1 @@ -Subproject commit e8f0568acb7312df815b5ccc236bb22129f82ee1 +Subproject commit 47e602e405f180c7973966bd21d82c80f5cbab46 diff --git a/community-build/community-projects/utest b/community-build/community-projects/utest index ee30db53faf7..2536c12247e8 160000 --- a/community-build/community-projects/utest +++ b/community-build/community-projects/utest @@ -1 +1 @@ -Subproject commit ee30db53faf7ca1b42eb58087812f1c7ae087150 +Subproject commit 2536c12247e80090377d21181b5ae5cd43ced8ee diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala index 9f26276348c7..9bb6b89a7dcd 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala @@ -2061,16 +2061,91 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext: type Constant = dotc.core.Constants.Constant object Constant extends ConstantModule: - def apply(x: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type): Constant = - dotc.core.Constants.Constant(x) - def unapply(constant: Constant): Option[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type] = - Some(constant.value.asInstanceOf[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type]) - object ClassTag extends ClassTagModule: - def apply[T](using x: Type): Constant = dotc.core.Constants.Constant(x) + + object Boolean extends ConstantBooleanModule: + def apply(x: Boolean): Constant = dotc.core.Constants.Constant(x) + def unapply(constant: Constant): Option[Boolean] = + if constant.tag == dotc.core.Constants.BooleanTag then Some(constant.booleanValue) + else None + end Boolean + + object Byte extends ConstantByteModule: + def apply(x: Byte): Constant = dotc.core.Constants.Constant(x) + def unapply(constant: Constant): Option[Byte] = + if constant.tag == dotc.core.Constants.ByteTag then Some(constant.byteValue) + else None + end Byte + + object Short extends ConstantShortModule: + def apply(x: Short): Constant = dotc.core.Constants.Constant(x) + def unapply(constant: Constant): Option[Short] = + if constant.tag == dotc.core.Constants.ShortTag then Some(constant.shortValue) + else None + end Short + + object Int extends ConstantIntModule: + def apply(x: Int): Constant = dotc.core.Constants.Constant(x) + def unapply(constant: Constant): Option[Int] = + if constant.tag == dotc.core.Constants.IntTag then Some(constant.intValue) + else None + end Int + + object Long extends ConstantLongModule: + def apply(x: Long): Constant = dotc.core.Constants.Constant(x) + def unapply(constant: Constant): Option[Long] = + if constant.tag == dotc.core.Constants.LongTag then Some(constant.longValue) + else None + end Long + + object Float extends ConstantFloatModule: + def apply(x: Float): Constant = dotc.core.Constants.Constant(x) + def unapply(constant: Constant): Option[Float] = + if constant.tag == dotc.core.Constants.FloatTag then Some(constant.floatValue) + else None + end Float + + object Double extends ConstantDoubleModule: + def apply(x: Double): Constant = dotc.core.Constants.Constant(x) + def unapply(constant: Constant): Option[Double] = + if constant.tag == dotc.core.Constants.DoubleTag then Some(constant.doubleValue) + else None + end Double + + object Char extends ConstantCharModule: + def apply(x: Char): Constant = dotc.core.Constants.Constant(x) + def unapply(constant: Constant): Option[Char] = + if constant.tag == dotc.core.Constants.CharTag then Some(constant.charValue) + else None + end Char + + object String extends ConstantStringModule: + def apply(x: String): Constant = dotc.core.Constants.Constant(x) + def unapply(constant: Constant): Option[String] = + if constant.tag == dotc.core.Constants.StringTag then Some(constant.stringValue) + else None + end String + + object Unit extends ConstantUnitModule: + def apply(): Constant = dotc.core.Constants.Constant(()) + def unapply(constant: Constant): Boolean = + constant.tag == dotc.core.Constants.UnitTag + end Unit + + object Null extends ConstantNullModule: + def apply(): Constant = dotc.core.Constants.Constant(null) + def unapply(constant: Constant): Boolean = + constant.tag == dotc.core.Constants.NullTag + end Null + + object ClassOf extends ConstantClassOfModule: + def apply(x: Type): Constant = + // TODO check that the type is a valid class when creating this constant or let Ycheck do it? + dotc.core.Constants.Constant(x) def unapply(constant: Constant): Option[Type] = if constant.tag == dotc.core.Constants.ClazzTag then Some(constant.typeValue) else None - end ClassTag + end ClassOf + end Constant object ConstantMethodsImpl extends ConstantMethods: diff --git a/library/src-bootstrapped/scala/internal/quoted/Expr.scala b/library/src-bootstrapped/scala/internal/quoted/Expr.scala index 33ea6c77dcb8..f95528529124 100644 --- a/library/src-bootstrapped/scala/internal/quoted/Expr.scala +++ b/library/src-bootstrapped/scala/internal/quoted/Expr.scala @@ -60,13 +60,13 @@ object Expr { /** Returns a null expresssion equivalent to `'{null}` */ def `null`: QuoteContext ?=> quoted.Expr[Null] = qctx ?=> { import qctx.tasty._ - Literal(Constant(null)).seal.asInstanceOf[quoted.Expr[Null]] + Literal(Constant.Null()).seal.asInstanceOf[quoted.Expr[Null]] } /** Returns a unit expresssion equivalent to `'{}` or `'{()}` */ def Unit: QuoteContext ?=> quoted.Expr[Unit] = qctx ?=> { import qctx.tasty._ - Literal(Constant(())).seal.asInstanceOf[quoted.Expr[Unit]] + Literal(Constant.Unit()).seal.asInstanceOf[quoted.Expr[Unit]] } } diff --git a/library/src-bootstrapped/scala/quoted/Liftable.scala b/library/src-bootstrapped/scala/quoted/Liftable.scala index e1ee9a06892e..8ef6a3191919 100644 --- a/library/src-bootstrapped/scala/quoted/Liftable.scala +++ b/library/src-bootstrapped/scala/quoted/Liftable.scala @@ -22,38 +22,66 @@ object Liftable { // IMPORTANT Keep in sync with tests/run-staging/liftables.scala /** Default liftable for Boolean */ - given BooleanLiftable[T <: Boolean] as Liftable[T] = new PrimitiveLiftable + given BooleanLiftable[T <: Boolean] as Liftable[T] { + def toExpr(x: T) = + import qctx.tasty._ + Literal(Constant.Boolean(x)).seal.asInstanceOf[Expr[T]] + } /** Default liftable for Byte */ - given ByteLiftable[T <: Byte] as Liftable[T] = new PrimitiveLiftable + given ByteLiftable[T <: Byte] as Liftable[T] { + def toExpr(x: T) = + import qctx.tasty._ + Literal(Constant.Byte(x)).seal.asInstanceOf[Expr[T]] + } /** Default liftable for Short */ - given ShortLiftable[T <: Short] as Liftable[T] = new PrimitiveLiftable + given ShortLiftable[T <: Short] as Liftable[T] { + def toExpr(x: T) = + import qctx.tasty._ + Literal(Constant.Short(x)).seal.asInstanceOf[Expr[T]] + } /** Default liftable for Int */ - given IntLiftable[T <: Int] as Liftable[T] = new PrimitiveLiftable + given IntLiftable[T <: Int] as Liftable[T] { + def toExpr(x: T) = + import qctx.tasty._ + Literal(Constant.Int(x)).seal.asInstanceOf[Expr[T]] + } /** Default liftable for Long */ - given LongLiftable[T <: Long] as Liftable[T] = new PrimitiveLiftable + given LongLiftable[T <: Long] as Liftable[T] { + def toExpr(x: T) = + import qctx.tasty._ + Literal(Constant.Long(x)).seal.asInstanceOf[Expr[T]] + } /** Default liftable for Float */ - given FloatLiftable[T <: Float] as Liftable[T] = new PrimitiveLiftable + given FloatLiftable[T <: Float] as Liftable[T] { + def toExpr(x: T) = + import qctx.tasty._ + Literal(Constant.Float(x)).seal.asInstanceOf[Expr[T]] + } /** Default liftable for Double */ - given DoubleLiftable[T <: Double] as Liftable[T] = new PrimitiveLiftable + given DoubleLiftable[T <: Double] as Liftable[T] { + def toExpr(x: T) = + import qctx.tasty._ + Literal(Constant.Double(x)).seal.asInstanceOf[Expr[T]] + } /** Default liftable for Char */ - given CharLiftable[T <: Char] as Liftable[T] = new PrimitiveLiftable + given CharLiftable[T <: Char] as Liftable[T] { + def toExpr(x: T) = + import qctx.tasty._ + Literal(Constant.Char(x)).seal.asInstanceOf[Expr[T]] + } /** Default liftable for String */ - given StringLiftable[T <: String] as Liftable[T] = new PrimitiveLiftable - - /** Lift a literal constant value */ - private class PrimitiveLiftable[T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends Liftable[T] { - def toExpr(x: T) = qctx ?=> { + given StringLiftable[T <: String] as Liftable[T] { + def toExpr(x: T) = import qctx.tasty._ - Literal(Constant(x)).seal.asInstanceOf[Expr[T]] - } + Literal(Constant.String(x)).seal.asInstanceOf[Expr[T]] } /** Default liftable for Class[T] */ diff --git a/library/src/scala/tasty/Reflection.scala b/library/src/scala/tasty/Reflection.scala index dfbde978a392..62f2b8795619 100644 --- a/library/src/scala/tasty/Reflection.scala +++ b/library/src/scala/tasty/Reflection.scala @@ -2317,25 +2317,144 @@ trait Reflection { reflection => /** Constant value represented as the constant itself */ type Constant <: AnyRef - /** Module of Constant literals */ + /** Constant value represented as the constant itself */ val Constant: ConstantModule + /** Constant value represented as the constant itself */ trait ConstantModule { this: Constant.type => - def apply(x: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type): Constant + /** Constant Boolean value */ + val Boolean: ConstantBooleanModule + + /** Constant Boolean value */ + trait ConstantBooleanModule { this: Boolean.type => + /** Create a constant Boolean value */ + def apply(x: Boolean): Constant + /** Match Boolean value constant and extract its value */ + def unapply(constant: Constant): Option[Boolean] + } + + /** Constant Byte value */ + val Byte: ConstantByteModule + + /** Constant Byte value */ + trait ConstantByteModule { this: Byte.type => + /** Create a constant Byte value */ + def apply(x: Byte): Constant + /** Match Byte value constant and extract its value */ + def unapply(constant: Constant): Option[Byte] + } + + /** Constant Short value */ + val Short: ConstantShortModule + + /** Constant Short value */ + trait ConstantShortModule { this: Short.type => + /** Create a constant Short value */ + def apply(x: Short): Constant + /** Match Short value constant and extract its value */ + def unapply(constant: Constant): Option[Short] + } + + /** Constant Int value */ + val Int: ConstantIntModule + + /** Constant Int value */ + trait ConstantIntModule { this: Int.type => + /** Create a constant Int value */ + def apply(x: Int): Constant + /** Match Int value constant and extract its value */ + def unapply(constant: Constant): Option[Int] + } + + /** Constant Long value */ + val Long: ConstantLongModule + + /** Constant Long value */ + trait ConstantLongModule { this: Long.type => + /** Create a constant Long value */ + def apply(x: Long): Constant + /** Match Long value constant and extract its value */ + def unapply(constant: Constant): Option[Long] + } + + /** Constant Float value */ + val Float: ConstantFloatModule - def unapply(constant: Constant): Option[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type] + /** Constant Float value */ + trait ConstantFloatModule { this: Float.type => + /** Create a constant Float value */ + def apply(x: Float): Constant + /** Match Float value constant and extract its value */ + def unapply(constant: Constant): Option[Float] + } + + /** Constant Double value */ + val Double: ConstantDoubleModule + + /** Constant Double value */ + trait ConstantDoubleModule { this: Double.type => + /** Create a constant Double value */ + def apply(x: Double): Constant + /** Match Double value constant and extract its value */ + def unapply(constant: Constant): Option[Double] + } + + /** Constant Char value */ + val Char: ConstantCharModule - /** Module of ClassTag literals */ - val ClassTag: ClassTagModule + /** Constant Char value */ + trait ConstantCharModule { this: Char.type => + /** Create a constant Char value */ + def apply(x: Char): Constant + /** Match Char value constant and extract its value */ + def unapply(constant: Constant): Option[Char] + } + + /** Constant String value */ + val String: ConstantStringModule + + /** Constant String value */ + trait ConstantStringModule { this: String.type => + /** Create a constant String value */ + def apply(x: String): Constant + /** Match String value constant and extract its value */ + def unapply(constant: Constant): Option[String] + } - /** Module of ClassTag literals */ - trait ClassTagModule { this: ClassTag.type => - /** scala.reflect.ClassTag literal */ - def apply[T](using x: Type): Constant - /** Extractor for ClassTag literals */ + /** Constant Unit value */ + val Unit: ConstantUnitModule + + /** Constant Unit value */ + trait ConstantUnitModule { this: Unit.type => + /** Create a constant Unit value */ + def apply(): Constant + /** Match Unit value constant */ + def unapply(constant: Constant): Boolean + } + + /** Constant null value */ + val Null: ConstantNullModule + + /** Constant null value */ + trait ConstantNullModule { this: Null.type => + /** Create a constant null value */ + def apply(): Constant + /** Match null value constant */ + def unapply(constant: Constant): Boolean + } + + /** Constant class value representing a `classOf[T]` */ + val ClassOf: ConstantClassOfModule + + /** Constant class value representing a `classOf[T]` */ + trait ConstantClassOfModule { this: ClassOf.type => + /** Create a constant class value representing `classOf[]` */ + def apply(tpe: Type): Constant + /** Match a class value constant representing `classOf[]` and extract its type */ def unapply(constant: Constant): Option[Type] } + } given ConstantMethods as ConstantMethods = ConstantMethodsImpl diff --git a/library/src/scala/tasty/reflect/ExtractorsPrinter.scala b/library/src/scala/tasty/reflect/ExtractorsPrinter.scala index 216c161a37e1..d8dc6fa7203d 100644 --- a/library/src/scala/tasty/reflect/ExtractorsPrinter.scala +++ b/library/src/scala/tasty/reflect/ExtractorsPrinter.scala @@ -165,19 +165,19 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val tasty: R) extends Print } def visitConstant(x: Constant): Buffer = x match { - case Constant(()) => this += "Constant(())" - case Constant(null) => this += "Constant(null)" - case Constant(value: Boolean) => this += "Constant(" += value += ")" - case Constant(value: Byte) => this += "Constant(" += value += ": Byte)" - case Constant(value: Short) => this += "Constant(" += value += ": Short)" - case Constant(value: Char) => this += "Constant('" += value += "')" - case Constant(value: Int) => this += "Constant(" += value.toString += ")" - case Constant(value: Long) => this += "Constant(" += value += "L)" - case Constant(value: Float) => this += "Constant(" += value += "f)" - case Constant(value: Double) => this += "Constant(" += value += "d)" - case Constant(value: String) => this += "Constant(\"" += value += "\")" - case Constant.ClassTag(value) => - this += "Constant.ClassTag(" + case Constant.Unit() => this += "Constant.Unit()" + case Constant.Null() => this += "Constant.Null()" + case Constant.Boolean(value) => this += "Constant.Boolean(" += value += ")" + case Constant.Byte(value) => this += "Constant.Byte(" += value += ")" + case Constant.Short(value) => this += "Constant.Short(" += value += ")" + case Constant.Int(value) => this += "Constant.Int(" += value += ")" + case Constant.Long(value) => this += "Constant.Long(" += value += "L)" + case Constant.Float(value) => this += "Constant.Float(" += value += "f)" + case Constant.Double(value) => this += "Constant.Double(" += value += "d)" + case Constant.Char(value) => this += "Constant.Char('" += value += "')" + case Constant.String(value) => this += "Constant.String(\"" += value += "\")" + case Constant.ClassOf(value) => + this += "Constant.ClassOf(" visitType(value) += ")" } diff --git a/library/src/scala/tasty/reflect/SourceCodePrinter.scala b/library/src/scala/tasty/reflect/SourceCodePrinter.scala index 20f3e6cddf2e..b4f74344b64c 100644 --- a/library/src/scala/tasty/reflect/SourceCodePrinter.scala +++ b/library/src/scala/tasty/reflect/SourceCodePrinter.scala @@ -279,7 +279,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig case While(cond, body) => (cond, body) match { - case (Block(Block(Nil, body1) :: Nil, Block(Nil, cond1)), Literal(Constant(()))) => + case (Block(Block(Nil, body1) :: Nil, Block(Nil, cond1)), Literal(Constant.Unit())) => this += highlightKeyword("do ") printTree(body1) += highlightKeyword(" while ") inParens(printTree(cond1)) @@ -555,7 +555,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig while (it.hasNext) extractFlatStats(it.next()) extractFlatStats(expansion) - case Literal(Constant(())) => // ignore + case Literal(Constant.Unit()) => // ignore case stat => flatStats += stat } def extractFlatExpr(term: Term): Term = term match { @@ -937,18 +937,18 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig inline private val qSc = '"' def printConstant(const: Constant): Buffer = const match { - case Constant(()) => this += highlightLiteral("()") - case Constant(null) => this += highlightLiteral("null") - case Constant(v: Boolean) => this += highlightLiteral(v.toString) - case Constant(v: Byte) => this += highlightLiteral(v.toString) - case Constant(v: Short) => this += highlightLiteral(v.toString) - case Constant(v: Int) => this += highlightLiteral(v.toString) - case Constant(v: Long) => this += highlightLiteral(v.toString + "L") - case Constant(v: Float) => this += highlightLiteral(v.toString + "f") - case Constant(v: Double) => this += highlightLiteral(v.toString) - case Constant(v: Char) => this += highlightString(s"${qc}${escapedChar(v)}${qc}") - case Constant(v: String) => this += highlightString(s"${qSc}${escapedString(v)}${qSc}") - case Constant.ClassTag(v) => + case Constant.Unit() => this += highlightLiteral("()") + case Constant.Null() => this += highlightLiteral("null") + case Constant.Boolean(v) => this += highlightLiteral(v.toString) + case Constant.Byte(v) => this += highlightLiteral(v.toString) + case Constant.Short(v) => this += highlightLiteral(v.toString) + case Constant.Int(v) => this += highlightLiteral(v.toString) + case Constant.Long(v) => this += highlightLiteral(v.toString + "L") + case Constant.Float(v) => this += highlightLiteral(v.toString + "f") + case Constant.Double(v) => this += highlightLiteral(v.toString) + case Constant.Char(v) => this += highlightString(s"${qc}${escapedChar(v)}${qc}") + case Constant.String(v) => this += highlightString(s"${qSc}${escapedString(v)}${qSc}") + case Constant.ClassOf(v) => this += "classOf" inSquare(printType(v)) } @@ -1414,8 +1414,8 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig private def splicedName(sym: Symbol): Option[String] = { sym.annots.find(_.symbol.owner == Symbol.requiredClass("scala.internal.quoted.showName")).flatMap { - case Apply(_, Literal(Constant(c: String)) :: Nil) => Some(c) - case Apply(_, Inlined(_, _, Literal(Constant(c: String))) :: Nil) => Some(c) + case Apply(_, Literal(Constant.String(c)) :: Nil) => Some(c) + case Apply(_, Inlined(_, _, Literal(Constant.String(c))) :: Nil) => Some(c) case annot => None }.orElse { if sym.owner.isClassDef then None diff --git a/tests/pos-macros/tasty-constant-type/Macro_1.scala b/tests/pos-macros/tasty-constant-type/Macro_1.scala index ba80aeac793c..42b1785f12e9 100644 --- a/tests/pos-macros/tasty-constant-type/Macro_1.scala +++ b/tests/pos-macros/tasty-constant-type/Macro_1.scala @@ -9,10 +9,10 @@ object Macro { def impl[A <: Int : Type, B <: Int : Type](a: Type[A], b: Type[B])(using qctx: QuoteContext) : Expr[AddInt[A, B]] = { import qctx.tasty._ - val ConstantType(Constant(v1: Int)) = a.unseal.tpe - val ConstantType(Constant(v2: Int)) = b.unseal.tpe + val ConstantType(Constant.Int(v1)) = a.unseal.tpe + val ConstantType(Constant.Int(v2)) = b.unseal.tpe - Literal(Constant((v1 + v2): Int)).tpe.seal match + Literal(Constant.Int(v1 + v2)).tpe.seal match case '[$t] => '{ null: AddInt[$a, $b] { type Out = $t } } } } diff --git a/tests/pos-macros/treemap-unapply/Macro.scala b/tests/pos-macros/treemap-unapply/Macro.scala index defd3cb29eca..08bebb7e6250 100644 --- a/tests/pos-macros/treemap-unapply/Macro.scala +++ b/tests/pos-macros/treemap-unapply/Macro.scala @@ -2,7 +2,7 @@ import scala.quoted._ inline def mcr(x: => Unit): Unit = ${mcrImpl('x)} def mcrImpl(x: Expr[Unit])(using ctx: QuoteContext) : Expr[Unit] = - import ctx.tasty.{ given _, _ } + import ctx.tasty._ val tr: Term = x.unseal object m extends TreeMap m.transformTerm(tr).seal.cast[Unit] diff --git a/tests/run-custom-args/Yretain-trees/tasty-definitions-2.check b/tests/run-custom-args/Yretain-trees/tasty-definitions-2.check index f487bcdcb6c2..114221a5a4a5 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-definitions-2.check +++ b/tests/run-custom-args/Yretain-trees/tasty-definitions-2.check @@ -1,3 +1,3 @@ -DefDef("foo", Nil, Nil, TypeIdent("Int"), Some(Apply(Select(Literal(Constant(1)), "+"), List(Literal(Constant(2)))))) -ValDef("bar", TypeIdent("Int"), Some(Apply(Select(Literal(Constant(2)), "+"), List(Literal(Constant(3)))))) +DefDef("foo", Nil, Nil, TypeIdent("Int"), Some(Apply(Select(Literal(Constant.Int(1)), "+"), List(Literal(Constant.Int(2)))))) +ValDef("bar", TypeIdent("Int"), Some(Apply(Select(Literal(Constant.Int(2)), "+"), List(Literal(Constant.Int(3)))))) Bind("x", Ident("_")) diff --git a/tests/run-custom-args/Yretain-trees/tasty-load-tree-1.check b/tests/run-custom-args/Yretain-trees/tasty-load-tree-1.check index 83c5fcea1695..335a80717346 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-load-tree-1.check +++ b/tests/run-custom-args/Yretain-trees/tasty-load-tree-1.check @@ -1,2 +1,2 @@ -DefDef("foo", Nil, Nil, TypeIdent("Int"), Some(Apply(Select(Literal(Constant(1)), "+"), List(Literal(Constant(2)))))) -ValDef("bar", TypeIdent("Int"), Some(Apply(Select(Literal(Constant(2)), "+"), List(Literal(Constant(3)))))) +DefDef("foo", Nil, Nil, TypeIdent("Int"), Some(Apply(Select(Literal(Constant.Int(1)), "+"), List(Literal(Constant.Int(2)))))) +ValDef("bar", TypeIdent("Int"), Some(Apply(Select(Literal(Constant.Int(2)), "+"), List(Literal(Constant.Int(3)))))) diff --git a/tests/run-macros/f-interpolation-1/FQuote_1.scala b/tests/run-macros/f-interpolation-1/FQuote_1.scala index 8119bd2daabb..1ba0f0e6b0c2 100644 --- a/tests/run-macros/f-interpolation-1/FQuote_1.scala +++ b/tests/run-macros/f-interpolation-1/FQuote_1.scala @@ -36,7 +36,7 @@ object FQuote { if isSCOpsConversion(conv) && isStringContextApply(fun) && values.forall(isStringConstant) => - values.collect { case Literal(Constant(value: String)) => value } + values.collect { case Literal(Constant.String(value)) => value } case tree => report.error(s"String literal expected, but ${tree.showExtractors} found") return '{???} diff --git a/tests/run-macros/i5119.check b/tests/run-macros/i5119.check index 121a865ee6e2..90c98e0a2c3b 100644 --- a/tests/run-macros/i5119.check +++ b/tests/run-macros/i5119.check @@ -1,2 +1,2 @@ -Select(Typed(Apply(Select(New(TypeIdent("StringContextOps")), ""), List(Apply(Select(Select(Select(Ident("_root_"), "scala"), "StringContext"), "apply"), List(Typed(Repeated(List(Literal(Constant("Hello World ")), Literal(Constant("!"))), Inferred()), Inferred()))))), TypeIdent("StringContextOps")), "inline$sc") -Typed(Repeated(List(Literal(Constant(1))), Inferred()), Inferred()) +Select(Typed(Apply(Select(New(TypeIdent("StringContextOps")), ""), List(Apply(Select(Select(Select(Ident("_root_"), "scala"), "StringContext"), "apply"), List(Typed(Repeated(List(Literal(Constant.String("Hello World ")), Literal(Constant.String("!"))), Inferred()), Inferred()))))), TypeIdent("StringContextOps")), "inline$sc") +Typed(Repeated(List(Literal(Constant.Int(1))), Inferred()), Inferred()) diff --git a/tests/run-macros/i5119b.check b/tests/run-macros/i5119b.check index 0a12abae43ae..3e1f5cde7707 100644 --- a/tests/run-macros/i5119b.check +++ b/tests/run-macros/i5119b.check @@ -1,4 +1,4 @@ -Apply(Ident("foo"), List(Literal(Constant(1)))) -Apply(Ident("foo"), List(Literal(Constant(2)))) -Apply(Ident("foo"), List(Literal(Constant(4)))) -Apply(Ident("foo"), List(Literal(Constant(3)))) +Apply(Ident("foo"), List(Literal(Constant.Int(1)))) +Apply(Ident("foo"), List(Literal(Constant.Int(2)))) +Apply(Ident("foo"), List(Literal(Constant.Int(4)))) +Apply(Ident("foo"), List(Literal(Constant.Int(3)))) diff --git a/tests/run-macros/i6988/FirstArg_1.scala b/tests/run-macros/i6988/FirstArg_1.scala index 0c32159803ab..b6f22c7dac0f 100644 --- a/tests/run-macros/i6988/FirstArg_1.scala +++ b/tests/run-macros/i6988/FirstArg_1.scala @@ -23,7 +23,7 @@ object Macros { else enclosingParamList(owner.owner) def literal(value: String): Expr[String] = - Literal(Constant(value)).seal.asInstanceOf[Expr[String]] + Literal(Constant.String(value)).seal.asInstanceOf[Expr[String]] val paramss = enclosingParamList(Symbol.currentOwner) val firstArg = paramss.flatten.head val ref = Select.unique(This(enclosingClass()), firstArg.name) diff --git a/tests/run-macros/i9812b/Macro_1.scala b/tests/run-macros/i9812b/Macro_1.scala index 808d82fadd4b..70b20db8a5cf 100644 --- a/tests/run-macros/i9812b/Macro_1.scala +++ b/tests/run-macros/i9812b/Macro_1.scala @@ -29,7 +29,7 @@ case object NIL extends Lst[Nothing] given IntLiftable[T <: Int] as Liftable[T]: def toExpr(x: T): QuoteContext ?=> Expr[T] = qctx ?=> { import qctx.tasty._ - Literal(Constant(x)).seal.asInstanceOf[Expr[T]] + Literal(Constant.Int(x)).seal.asInstanceOf[Expr[T]] } given LiftLst[T: Type: Liftable](using ev1: => Liftable[CONS[T]], ev2: => Liftable[NIL.type]) as Liftable[Lst[T]]: diff --git a/tests/run-macros/refined-selectable-macro/Macro_1.scala b/tests/run-macros/refined-selectable-macro/Macro_1.scala index 1a1642b21644..811db10c2b03 100644 --- a/tests/run-macros/refined-selectable-macro/Macro_1.scala +++ b/tests/run-macros/refined-selectable-macro/Macro_1.scala @@ -58,7 +58,7 @@ object Macro { def extractTuple(tpe: Type, seen: Set[String]): (Set[String], (String, Type)) = { tpe match { // Tuple2(S, T) where S must be a constant string type - case AppliedType(parent, ConstantType(Constant(name: String)) :: (info: Type) :: Nil) if (parent.typeSymbol == defn.TupleClass(2)) => + case AppliedType(parent, ConstantType(Constant.String(name)) :: (info: Type) :: Nil) if (parent.typeSymbol == defn.TupleClass(2)) => if seen(name) then report.error(s"Repeated record name: $name", s) (seen + name, (name, info)) diff --git a/tests/run-macros/tasty-argument-tree-1.check b/tests/run-macros/tasty-argument-tree-1.check index 9f400af67132..b813a59e5244 100644 --- a/tests/run-macros/tasty-argument-tree-1.check +++ b/tests/run-macros/tasty-argument-tree-1.check @@ -1,15 +1,15 @@ -tree: Inlined(None, Nil, Literal(Constant(3))) -tree deref. vals: Literal(Constant(3)) +tree: Inlined(None, Nil, Literal(Constant.Int(3))) +tree deref. vals: Literal(Constant.Int(3)) tree: Inlined(None, Nil, Ident("v")) -tree deref. vals: Literal(Constant(1)) +tree deref. vals: Literal(Constant.Int(1)) tree: Inlined(None, Nil, Ident("x$proxy1")) -tree deref. vals: Literal(Constant(2)) +tree deref. vals: Literal(Constant.Int(2)) tree: Inlined(None, Nil, Ident("l")) -tree deref. vals: Literal(Constant(3)) +tree deref. vals: Literal(Constant.Int(3)) tree: Inlined(None, Nil, Ident("a")) tree deref. vals: Ident("a") @@ -21,22 +21,22 @@ tree: Inlined(None, Nil, Ident("x$proxy3")) tree deref. vals: Apply(Ident("d2"), Nil) tree: Inlined(None, Nil, Ident("x$proxy4")) -tree deref. vals: Apply(Ident("d3"), List(Literal(Constant(3)))) +tree deref. vals: Apply(Ident("d3"), List(Literal(Constant.Int(3)))) tree: Inlined(None, Nil, Ident("x$proxy5")) tree deref. vals: TypeApply(Ident("d4"), List(TypeIdent("Int"))) tree: Inlined(None, Nil, Ident("vv")) -tree deref. vals: Literal(Constant(1)) +tree deref. vals: Literal(Constant.Int(1)) tree: Inlined(None, Nil, Ident("x$proxy6")) -tree deref. vals: Literal(Constant(1)) +tree deref. vals: Literal(Constant.Int(1)) tree: Inlined(None, Nil, Ident("vd")) -tree deref. vals: Literal(Constant(2)) +tree deref. vals: Literal(Constant.Int(2)) tree: Inlined(None, Nil, Ident("x$proxy7")) -tree deref. vals: Literal(Constant(2)) +tree deref. vals: Literal(Constant.Int(2)) tree: Inlined(None, Nil, Ident("x$proxy8")) -tree deref. vals: Apply(TypeApply(Select(Ident("Tuple2"), "apply"), List(Inferred(), Inferred())), List(Literal(Constant(1)), Literal(Constant(2)))) +tree deref. vals: Apply(TypeApply(Select(Ident("Tuple2"), "apply"), List(Inferred(), Inferred())), List(Literal(Constant.Int(1)), Literal(Constant.Int(2)))) diff --git a/tests/run-macros/tasty-construct-types/Macro_1.scala b/tests/run-macros/tasty-construct-types/Macro_1.scala index 971fe363ebb5..0355c34be93b 100644 --- a/tests/run-macros/tasty-construct-types/Macro_1.scala +++ b/tests/run-macros/tasty-construct-types/Macro_1.scala @@ -14,9 +14,9 @@ object Macros { def theTestBlockImpl(using qctx : QuoteContext) : Expr[Unit] = { import qctx.tasty._ - val x1T = ConstantType(Constant(1)) - val x2T = OrType(ConstantType(Constant(1)), ConstantType(Constant(2))) - val x3T = AndType(ConstantType(Constant(3)), Type.of[Any]) + val x1T = ConstantType(Constant.Int(1)) + val x2T = OrType(ConstantType(Constant.Int(1)), ConstantType(Constant.Int(2))) + val x3T = AndType(ConstantType(Constant.Int(3)), Type.of[Any]) val x4T = TypeLambda( List("A","B"), @@ -28,7 +28,7 @@ object Macros { "T", TypeBounds(Type.of[Int], Type.of[Int])) val x6T = Type.of[List].appliedTo(List(Type.of[Int])) - val x7T = AnnotatedType(ConstantType(Constant(7)), '{ new TestAnnotation }.unseal) + val x7T = AnnotatedType(ConstantType(Constant.Int(7)), '{ new TestAnnotation }.unseal) val x8T = MatchType( Type.of[Int], diff --git a/tests/run-macros/tasty-create-method-symbol/Macro_1.scala b/tests/run-macros/tasty-create-method-symbol/Macro_1.scala index c7117b5cb438..94746641124c 100644 --- a/tests/run-macros/tasty-create-method-symbol/Macro_1.scala +++ b/tests/run-macros/tasty-create-method-symbol/Macro_1.scala @@ -23,7 +23,7 @@ object Macros { Some('{ ${ a.seal.asInstanceOf[Expr[Int]] } - ${ b.seal.asInstanceOf[Expr[Int]] } }.unseal) } }), - '{ assert(${ Apply(Ref(sym1), List(Literal(Constant(2)), Literal(Constant(3)))).seal.asInstanceOf[Expr[Int]] } == -1) }.unseal) + '{ assert(${ Apply(Ref(sym1), List(Literal(Constant.Int(2)), Literal(Constant.Int(3)))).seal.asInstanceOf[Expr[Int]] } == -1) }.unseal) // test for no argument list (no Apply node) val sym2 : Symbol = Symbol.newMethod( @@ -36,7 +36,7 @@ object Macros { DefDef(sym2, { case List() => { case List() => - Some(Literal(Constant(2))) + Some(Literal(Constant.Int(2))) } }), '{ assert(${ Ref(sym2).seal.asInstanceOf[Expr[Int]] } == 2) }.unseal) @@ -59,7 +59,7 @@ object Macros { Some(a) } }), - '{ assert(${ Apply(Apply(Ref(sym3), List(Literal(Constant(3)))), List(Literal(Constant(3)))).seal.asInstanceOf[Expr[Int]] } == 3) }.unseal) + '{ assert(${ Apply(Apply(Ref(sym3), List(Literal(Constant.Int(3)))), List(Literal(Constant.Int(3)))).seal.asInstanceOf[Expr[Int]] } == 3) }.unseal) // test for recursive references val sym4 : Symbol = Symbol.newMethod( @@ -81,7 +81,7 @@ object Macros { }.unseal) } }), - '{ assert(${ Apply(Ref(sym4), List(Literal(Constant(4)))).seal.asInstanceOf[Expr[Int]] } == 0) }.unseal) + '{ assert(${ Apply(Ref(sym4), List(Literal(Constant.Int(4)))).seal.asInstanceOf[Expr[Int]] } == 0) }.unseal) // test for nested functions (one symbol is the other's parent, and we use a Closure) val sym5 : Symbol = Symbol.newMethod( @@ -115,7 +115,7 @@ object Macros { } } }), - '{ assert(${ Apply(Ref(sym5), List(Literal(Constant(5)))).seal.asInstanceOf[Expr[Int=>Int]] }(4) == 1) }.unseal) + '{ assert(${ Apply(Ref(sym5), List(Literal(Constant.Int(5)))).seal.asInstanceOf[Expr[Int=>Int]] }(4) == 1) }.unseal) // test mutually recursive definitions val sym6_1 : Symbol = Symbol.newMethod( @@ -162,7 +162,7 @@ object Macros { } }), - '{ assert(${ Apply(Ref(sym6_2), List(Literal(Constant(6)))).seal.asInstanceOf[Expr[Int]] } == 0) }.unseal) + '{ assert(${ Apply(Ref(sym6_2), List(Literal(Constant.Int(6)))).seal.asInstanceOf[Expr[Int]] } == 0) }.unseal) // test polymorphic methods by synthesizing an identity method val sym7 : Symbol = Symbol.newMethod( @@ -182,7 +182,7 @@ object Macros { Some(Typed(x, Inferred(t))) } }), - '{ assert(${ Apply(TypeApply(Ref(sym7), List(Inferred(Type.of[Int]))), List(Literal(Constant(7)))).seal.asInstanceOf[Expr[Int]] } == 7) }.unseal) + '{ assert(${ Apply(TypeApply(Ref(sym7), List(Inferred(Type.of[Int]))), List(Literal(Constant.Int(7)))).seal.asInstanceOf[Expr[Int]] } == 7) }.unseal) Block( sym1Statements ++ @@ -193,7 +193,7 @@ object Macros { sym6Statements ++ sym7Statements ++ List('{ println("Ok") }.unseal), - Literal(Constant(()))).seal.asInstanceOf[Expr[Unit]] + Literal(Constant.Unit())).seal.asInstanceOf[Expr[Unit]] } } diff --git a/tests/run-macros/tasty-eval/quoted_1.scala b/tests/run-macros/tasty-eval/quoted_1.scala index 10433ac3e9c8..dd1f01aafa62 100644 --- a/tests/run-macros/tasty-eval/quoted_1.scala +++ b/tests/run-macros/tasty-eval/quoted_1.scala @@ -24,10 +24,10 @@ object Macros { pre.termSymbol.tree match case t: ValDef => t.tpt.tpe match { - case ConstantType(Constant(i: Int)) => Some(i) + case ConstantType(Constant.Int(i)) => Some(i) case _ => None } - case ConstantType(Constant(i: Int)) => Some(i) + case ConstantType(Constant.Int(i)) => Some(i) case _ => None } } diff --git a/tests/run-macros/tasty-extractors-1.check b/tests/run-macros/tasty-extractors-1.check index d239fffd4f2e..4f6d55b9e07e 100644 --- a/tests/run-macros/tasty-extractors-1.check +++ b/tests/run-macros/tasty-extractors-1.check @@ -1,120 +1,120 @@ -Inlined(None, Nil, Literal(Constant(true))) -ConstantType(Constant(true)) +Inlined(None, Nil, Literal(Constant.Boolean(true))) +ConstantType(Constant.Boolean(true)) -Inlined(None, Nil, Literal(Constant(1))) -ConstantType(Constant(1)) +Inlined(None, Nil, Literal(Constant.Int(1))) +ConstantType(Constant.Int(1)) -Inlined(None, Nil, Literal(Constant(2L))) -ConstantType(Constant(2L)) +Inlined(None, Nil, Literal(Constant.Long(2L))) +ConstantType(Constant.Long(2L)) -Inlined(None, Nil, Literal(Constant(2.1f))) -ConstantType(Constant(2.1f)) +Inlined(None, Nil, Literal(Constant.Float(2.1f))) +ConstantType(Constant.Float(2.1f)) -Inlined(None, Nil, Literal(Constant(2.2d))) -ConstantType(Constant(2.2d)) +Inlined(None, Nil, Literal(Constant.Double(2.2d))) +ConstantType(Constant.Double(2.2d)) -Inlined(None, Nil, Literal(Constant("abc"))) -ConstantType(Constant("abc")) +Inlined(None, Nil, Literal(Constant.String("abc"))) +ConstantType(Constant.String("abc")) -Inlined(None, Nil, Apply(Ident("println"), List(Literal(Constant("abc"))))) +Inlined(None, Nil, Apply(Ident("println"), List(Literal(Constant.String("abc"))))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Typed(Literal(Constant(8)), TypeIdent("Int"))) +Inlined(None, Nil, Typed(Literal(Constant.Int(8)), TypeIdent("Int"))) TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int") -Inlined(None, Nil, Typed(Literal(Constant(8: Byte)), TypeIdent("Byte"))) +Inlined(None, Nil, Typed(Literal(Constant.Byte(8)), TypeIdent("Byte"))) TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Byte") -Inlined(None, Nil, Typed(Literal(Constant(8: Short)), TypeIdent("Short"))) +Inlined(None, Nil, Typed(Literal(Constant.Short(8)), TypeIdent("Short"))) TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Short") -Inlined(None, Nil, Literal(Constant('a'))) -ConstantType(Constant('a')) +Inlined(None, Nil, Literal(Constant.Char('a'))) +ConstantType(Constant.Char('a')) -Inlined(None, Nil, Block(List(Literal(Constant(1)), Literal(Constant(2))), Literal(Constant(3)))) -ConstantType(Constant(3)) +Inlined(None, Nil, Block(List(Literal(Constant.Int(1)), Literal(Constant.Int(2))), Literal(Constant.Int(3)))) +ConstantType(Constant.Int(3)) -Inlined(None, Nil, If(Typed(Literal(Constant(true)), TypeIdent("Boolean")), Literal(Constant(1)), Literal(Constant(2)))) -OrType(ConstantType(Constant(1)), ConstantType(Constant(2))) +Inlined(None, Nil, If(Typed(Literal(Constant.Boolean(true)), TypeIdent("Boolean")), Literal(Constant.Int(1)), Literal(Constant.Int(2)))) +OrType(ConstantType(Constant.Int(1)), ConstantType(Constant.Int(2))) -Inlined(None, Nil, Match(Literal(Constant("a")), List(CaseDef(Literal(Constant("a")), None, Block(Nil, Literal(Constant(()))))))) +Inlined(None, Nil, Match(Literal(Constant.String("a")), List(CaseDef(Literal(Constant.String("a")), None, Block(Nil, Literal(Constant.Unit())))))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Match(Literal(Constant("b")), List(CaseDef(Bind("n", Ident("_")), None, Block(Nil, Literal(Constant(()))))))) +Inlined(None, Nil, Match(Literal(Constant.String("b")), List(CaseDef(Bind("n", Ident("_")), None, Block(Nil, Literal(Constant.Unit())))))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Match(Literal(Constant("c")), List(CaseDef(Bind("n", Typed(Ident("_"), TypeIdent("String"))), None, Block(Nil, Literal(Constant(()))))))) +Inlined(None, Nil, Match(Literal(Constant.String("c")), List(CaseDef(Bind("n", Typed(Ident("_"), TypeIdent("String"))), None, Block(Nil, Literal(Constant.Unit())))))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Match(Literal(Constant("e")), List(CaseDef(Ident("_"), None, Block(Nil, Literal(Constant(()))))))) +Inlined(None, Nil, Match(Literal(Constant.String("e")), List(CaseDef(Ident("_"), None, Block(Nil, Literal(Constant.Unit())))))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Match(Literal(Constant("f")), List(CaseDef(Typed(Ident("_"), TypeIdent("String")), None, Block(Nil, Literal(Constant(()))))))) +Inlined(None, Nil, Match(Literal(Constant.String("f")), List(CaseDef(Typed(Ident("_"), TypeIdent("String")), None, Block(Nil, Literal(Constant.Unit())))))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Match(Typed(Literal(Constant("g")), TypeIdent("Any")), List(CaseDef(Alternative(List(Typed(Ident("_"), TypeIdent("String")), Typed(Ident("_"), TypeIdent("Int")))), None, Block(Nil, Literal(Constant(()))))))) +Inlined(None, Nil, Match(Typed(Literal(Constant.String("g")), TypeIdent("Any")), List(CaseDef(Alternative(List(Typed(Ident("_"), TypeIdent("String")), Typed(Ident("_"), TypeIdent("Int")))), None, Block(Nil, Literal(Constant.Unit())))))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Match(Literal(Constant("h")), List(CaseDef(Ident("_"), Some(Literal(Constant(false))), Block(Nil, Literal(Constant(()))))))) +Inlined(None, Nil, Match(Literal(Constant.String("h")), List(CaseDef(Ident("_"), Some(Literal(Constant.Boolean(false))), Block(Nil, Literal(Constant.Unit())))))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ValDef("a", Inferred(), Some(Literal(Constant("o"))))), Match(Literal(Constant("i")), List(CaseDef(Bind("a", Ident("_")), None, Block(Nil, Literal(Constant(())))))))) +Inlined(None, Nil, Block(List(ValDef("a", Inferred(), Some(Literal(Constant.String("o"))))), Match(Literal(Constant.String("i")), List(CaseDef(Bind("a", Ident("_")), None, Block(Nil, Literal(Constant.Unit()))))))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Match(Ident("Nil"), List(CaseDef(Unapply(TypeApply(Select(Ident("List"), "unapplySeq"), List(Inferred())), Nil, List(Bind("a", Ident("_")), Bind("b", Ident("_")), Bind("c", Ident("_")))), None, Block(Nil, Literal(Constant(()))))))) +Inlined(None, Nil, Match(Ident("Nil"), List(CaseDef(Unapply(TypeApply(Select(Ident("List"), "unapplySeq"), List(Inferred())), Nil, List(Bind("a", Ident("_")), Bind("b", Ident("_")), Bind("c", Ident("_")))), None, Block(Nil, Literal(Constant.Unit())))))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Try(Literal(Constant(1)), List(CaseDef(Ident("_"), None, Block(Nil, Literal(Constant(()))))), None)) -OrType(ConstantType(Constant(1)), TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit")) +Inlined(None, Nil, Try(Literal(Constant.Int(1)), List(CaseDef(Ident("_"), None, Block(Nil, Literal(Constant.Unit())))), None)) +OrType(ConstantType(Constant.Int(1)), TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit")) -Inlined(None, Nil, Try(Literal(Constant(2)), Nil, Some(Literal(Constant(()))))) -ConstantType(Constant(2)) +Inlined(None, Nil, Try(Literal(Constant.Int(2)), Nil, Some(Literal(Constant.Unit())))) +ConstantType(Constant.Int(2)) -Inlined(None, Nil, Try(Literal(Constant(3)), List(CaseDef(Ident("_"), None, Block(Nil, Literal(Constant(()))))), Some(Literal(Constant(()))))) -OrType(ConstantType(Constant(3)), TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit")) +Inlined(None, Nil, Try(Literal(Constant.Int(3)), List(CaseDef(Ident("_"), None, Block(Nil, Literal(Constant.Unit())))), Some(Literal(Constant.Unit())))) +OrType(ConstantType(Constant.Int(3)), TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit")) -Inlined(None, Nil, Apply(Select(Literal(Constant("a")), "=="), List(Literal(Constant("b"))))) +Inlined(None, Nil, Apply(Select(Literal(Constant.String("a")), "=="), List(Literal(Constant.String("b"))))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Boolean") Inlined(None, Nil, Apply(Select(New(TypeIdent("Object")), ""), Nil)) TypeRef(ThisType(TypeRef(NoPrefix(), "lang")), "Object") -Inlined(None, Nil, Apply(Select(Ident("Int"), "box"), List(NamedArg("x", Literal(Constant(9)))))) +Inlined(None, Nil, Apply(Select(Ident("Int"), "box"), List(NamedArg("x", Literal(Constant.Int(9)))))) TypeRef(ThisType(TypeRef(NoPrefix(), "lang")), "Integer") Inlined(None, Nil, Apply(TypeApply(Select(Ident("Ordering"), "apply"), List(TypeIdent("Int"))), List(Ident("Int")))) AppliedType(TypeRef(ThisType(TypeRef(NoPrefix(), "math")), "Ordering"), List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int"))) -Inlined(None, Nil, Block(List(ValDef("a", TypeIdent("Int"), Some(Literal(Constant(3))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ValDef("a", TypeIdent("Int"), Some(Literal(Constant.Int(3))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ValDef("b", TypeIdent("Int"), Some(Literal(Constant(3))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ValDef("b", TypeIdent("Int"), Some(Literal(Constant.Int(3))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(DefDef("f1", Nil, Nil, TypeIdent("Int"), Some(Literal(Constant(3))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(DefDef("f1", Nil, Nil, TypeIdent("Int"), Some(Literal(Constant.Int(3))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(DefDef("f2", Nil, Nil, TypeIdent("Int"), Some(Return(Literal(Constant(4)))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(DefDef("f2", Nil, Nil, TypeIdent("Int"), Some(Return(Literal(Constant.Int(4)))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(DefDef("f3", Nil, List(List(ValDef("i", TypeIdent("Int"), None))), TypeIdent("Int"), Some(Ident("i")))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(DefDef("f3", Nil, List(List(ValDef("i", TypeIdent("Int"), None))), TypeIdent("Int"), Some(Ident("i")))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(DefDef("f4", Nil, List(List(ValDef("i", TypeIdent("Int"), None)), List(ValDef("j", TypeIdent("Int"), None))), TypeIdent("Int"), Some(Apply(Select(Ident("i"), "+"), List(Ident("j")))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(DefDef("f4", Nil, List(List(ValDef("i", TypeIdent("Int"), None)), List(ValDef("j", TypeIdent("Int"), None))), TypeIdent("Int"), Some(Apply(Select(Ident("i"), "+"), List(Ident("j")))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(DefDef("f5", Nil, List(List(ValDef("i", TypeIdent("Int"), None))), TypeIdent("Int"), Some(Ident("i"))), DefDef("f5$default$1", Nil, Nil, Inferred(), Some(Literal(Constant(9))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(DefDef("f5", Nil, List(List(ValDef("i", TypeIdent("Int"), None))), TypeIdent("Int"), Some(Ident("i"))), DefDef("f5$default$1", Nil, Nil, Inferred(), Some(Literal(Constant.Int(9))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(DefDef("f6", List(TypeDef("T", TypeBoundsTree(Inferred(), Inferred()))), List(List(ValDef("x", TypeIdent("T"), None))), TypeIdent("T"), Some(Ident("x")))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(DefDef("f6", List(TypeDef("T", TypeBoundsTree(Inferred(), Inferred()))), List(List(ValDef("x", TypeIdent("T"), None))), TypeIdent("T"), Some(Ident("x")))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(DefDef("f7", List(TypeDef("T", TypeBoundsTree(Inferred(), Inferred()))), List(List(ValDef("x", TypeIdent("T"), None))), Singleton(Ident("x")), Some(Ident("x")))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(DefDef("f7", List(TypeDef("T", TypeBoundsTree(Inferred(), Inferred()))), List(List(ValDef("x", TypeIdent("T"), None))), Singleton(Ident("x")), Some(Ident("x")))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(DefDef("f8", Nil, List(List(ValDef("i", Annotated(Applied(Inferred(), List(TypeIdent("Int"))), Apply(Select(New(Inferred()), ""), Nil)), None))), TypeIdent("Int"), Some(Literal(Constant(9))))), Apply(Ident("f8"), List(Typed(Repeated(List(Literal(Constant(1)), Literal(Constant(2)), Literal(Constant(3))), Inferred()), Inferred()))))) +Inlined(None, Nil, Block(List(DefDef("f8", Nil, List(List(ValDef("i", Annotated(Applied(Inferred(), List(TypeIdent("Int"))), Apply(Select(New(Inferred()), ""), Nil)), None))), TypeIdent("Int"), Some(Literal(Constant.Int(9))))), Apply(Ident("f8"), List(Typed(Repeated(List(Literal(Constant.Int(1)), Literal(Constant.Int(2)), Literal(Constant.Int(3))), Inferred()), Inferred()))))) TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int") -Inlined(None, Nil, Block(List(DefDef("f9", Nil, List(List(ValDef("i", ByName(TypeIdent("Int")), None))), TypeIdent("Int"), Some(Ident("i")))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(DefDef("f9", Nil, List(List(ValDef("i", ByName(TypeIdent("Int")), None))), TypeIdent("Int"), Some(Ident("i")))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") diff --git a/tests/run-macros/tasty-extractors-2.check b/tests/run-macros/tasty-extractors-2.check index f03e795c3bc4..0d9857e88e3f 100644 --- a/tests/run-macros/tasty-extractors-2.check +++ b/tests/run-macros/tasty-extractors-2.check @@ -1,4 +1,4 @@ -Inlined(None, Nil, Block(List(ValDef("x", Inferred(), Some(Literal(Constant(1))))), Assign(Ident("x"), Literal(Constant(2))))) +Inlined(None, Nil, Block(List(ValDef("x", Inferred(), Some(Literal(Constant.Int(1))))), Assign(Ident("x"), Literal(Constant.Int(2))))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Block(List(DefDef("$anonfun", Nil, List(List(ValDef("x", TypeIdent("Int"), None))), Inferred(), Some(Ident("x")))), Closure(Ident("$anonfun"), None))) @@ -7,10 +7,10 @@ AppliedType(TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Function1"), List(T Inlined(None, Nil, Ident("???")) TermRef(TermRef(ThisType(TypeRef(NoPrefix(), "scala")), "Predef"), "???") -Inlined(None, Nil, Literal(Constant(1))) -ConstantType(Constant(1)) +Inlined(None, Nil, Literal(Constant.Int(1))) +ConstantType(Constant.Int(1)) -Inlined(None, Nil, Typed(Literal(Constant(1)), TypeIdent("Int"))) +Inlined(None, Nil, Typed(Literal(Constant.Int(1)), TypeIdent("Int"))) TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int") Inlined(None, Nil, Typed(Ident("Nil"), Applied(TypeIdent("List"), List(TypeIdent("Int"))))) @@ -19,87 +19,87 @@ AppliedType(TypeRef(ThisType(TypeRef(NoPrefix(), "immutable")), "List"), List(Ty Inlined(None, Nil, Typed(Apply(Select(New(TypeIdent("Baz")), ""), Nil), Applied(TypeIdent("&"), List(TypeIdent("Foo"), TypeIdent("Bar"))))) AndType(TypeRef(ThisType(TypeRef(NoPrefix(), "")), "Foo"), TypeRef(ThisType(TypeRef(NoPrefix(), "")), "Bar")) -Inlined(None, Nil, Typed(Literal(Constant(1)), Applied(TypeIdent("|"), List(TypeIdent("Int"), TypeIdent("String"))))) +Inlined(None, Nil, Typed(Literal(Constant.Int(1)), Applied(TypeIdent("|"), List(TypeIdent("Int"), TypeIdent("String"))))) OrType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int"), TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "scala")), "Predef"), "String")) -Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, Nil)), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, Nil)), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ValDef("Foo", TypeIdent("Foo$"), Some(Apply(Select(New(TypeIdent("Foo$")), ""), Nil))), ClassDef("Foo$", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, Some(ValDef("_", Singleton(Ident("Foo")), None)), Nil)), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ValDef("Foo", TypeIdent("Foo$"), Some(Apply(Select(New(TypeIdent("Foo$")), ""), Nil))), ClassDef("Foo$", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, Some(ValDef("_", Singleton(Ident("Foo")), None)), Nil)), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(TypeDef("Foo", TypeBoundsTree(Inferred(), Inferred()))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(TypeDef("Foo", TypeBoundsTree(Inferred(), Inferred()))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(TypeDef("Foo", TypeIdent("Int"))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(TypeDef("Foo", TypeIdent("Int"))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(TypeDef("Foo", TypeBoundsTree(TypeIdent("Null"), TypeIdent("Object")))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(TypeDef("Foo", TypeBoundsTree(TypeIdent("Null"), TypeIdent("Object")))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), Some(Literal(Constant(0)))), DefDef("a_=", Nil, List(List(ValDef("x$1", Inferred(), None))), Inferred(), Some(Literal(Constant(()))))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), Some(Literal(Constant.Int(0)))), DefDef("a_=", Nil, List(List(ValDef("x$1", Inferred(), None))), Inferred(), Some(Literal(Constant.Unit())))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(DefDef("a", Nil, Nil, Inferred(), Some(Literal(Constant(0))))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(DefDef("a", Nil, Nil, Inferred(), Some(Literal(Constant.Int(0))))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(DefDef("a", Nil, Nil, Inferred(), Some(Literal(Constant(0))))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(DefDef("a", Nil, Nil, Inferred(), Some(Literal(Constant.Int(0))))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(DefDef("a", Nil, Nil, Inferred(), Some(Literal(Constant(0))))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(DefDef("a", Nil, Nil, Inferred(), Some(Literal(Constant.Int(0))))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil), TypeSelect(Select(Ident("_root_"), "scala"), "Product"), TypeSelect(Select(Ident("_root_"), "scala"), "Serializable")), Nil, None, List(DefDef("copy", Nil, List(Nil), Inferred(), Some(Apply(Select(New(Inferred()), ""), Nil))))), ValDef("Foo", TypeIdent("Foo$"), Some(Apply(Select(New(TypeIdent("Foo$")), ""), Nil))), ClassDef("Foo$", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil), Applied(Inferred(), List(Inferred()))), Nil, Some(ValDef("_", Singleton(Ident("Foo")), None)), List(DefDef("apply", Nil, List(Nil), Inferred(), Some(Apply(Select(New(Inferred()), ""), Nil))), DefDef("unapply", Nil, List(List(ValDef("x$1", Inferred(), None))), Singleton(Literal(Constant(true))), Some(Literal(Constant(true)))), DefDef("toString", Nil, Nil, Inferred(), Some(Literal(Constant("Foo"))))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil), TypeSelect(Select(Ident("_root_"), "scala"), "Product"), TypeSelect(Select(Ident("_root_"), "scala"), "Serializable")), Nil, None, List(DefDef("copy", Nil, List(Nil), Inferred(), Some(Apply(Select(New(Inferred()), ""), Nil))))), ValDef("Foo", TypeIdent("Foo$"), Some(Apply(Select(New(TypeIdent("Foo$")), ""), Nil))), ClassDef("Foo$", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil), Applied(Inferred(), List(Inferred()))), Nil, Some(ValDef("_", Singleton(Ident("Foo")), None)), List(DefDef("apply", Nil, List(Nil), Inferred(), Some(Apply(Select(New(Inferred()), ""), Nil))), DefDef("unapply", Nil, List(List(ValDef("x$1", Inferred(), None))), Singleton(Literal(Constant.Boolean(true))), Some(Literal(Constant.Boolean(true)))), DefDef("toString", Nil, Nil, Inferred(), Some(Literal(Constant.String("Foo"))))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo1", DefDef("", Nil, List(List(ValDef("a", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), None)))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo1", DefDef("", Nil, List(List(ValDef("a", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), None)))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo2", DefDef("", Nil, List(List(ValDef("b", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("b", Inferred(), None)))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo2", DefDef("", Nil, List(List(ValDef("b", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("b", Inferred(), None)))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo3", DefDef("", Nil, List(List(ValDef("a", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), None))), ValDef("Foo3", TypeIdent("Foo3$"), Some(Apply(Select(New(TypeIdent("Foo3$")), ""), Nil))), ClassDef("Foo3$", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, Some(ValDef("_", Singleton(Ident("Foo3")), None)), List(DefDef("$lessinit$greater$default$1", Nil, Nil, Inferred(), Some(Literal(Constant(5))))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo3", DefDef("", Nil, List(List(ValDef("a", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), None))), ValDef("Foo3", TypeIdent("Foo3$"), Some(Apply(Select(New(TypeIdent("Foo3$")), ""), Nil))), ClassDef("Foo3$", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, Some(ValDef("_", Singleton(Ident("Foo3")), None)), List(DefDef("$lessinit$greater$default$1", Nil, Nil, Inferred(), Some(Literal(Constant.Int(5))))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo4", DefDef("", Nil, List(List(ValDef("a", TypeIdent("Int"), None)), List(ValDef("b", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), None), ValDef("b", Inferred(), None)))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo4", DefDef("", Nil, List(List(ValDef("a", TypeIdent("Int"), None)), List(ValDef("b", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), None), ValDef("b", Inferred(), None)))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo5", DefDef("", Nil, List(List(ValDef("a", TypeIdent("Int"), None)), List(ValDef("b", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), None), ValDef("b", Inferred(), None))), ValDef("Foo5", TypeIdent("Foo5$"), Some(Apply(Select(New(TypeIdent("Foo5$")), ""), Nil))), ClassDef("Foo5$", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, Some(ValDef("_", Singleton(Ident("Foo5")), None)), List(DefDef("$lessinit$greater$default$2", Nil, List(List(ValDef("a", TypeIdent("Int"), None))), Inferred(), Some(Ident("a")))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo5", DefDef("", Nil, List(List(ValDef("a", TypeIdent("Int"), None)), List(ValDef("b", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), None), ValDef("b", Inferred(), None))), ValDef("Foo5", TypeIdent("Foo5$"), Some(Apply(Select(New(TypeIdent("Foo5$")), ""), Nil))), ClassDef("Foo5$", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, Some(ValDef("_", Singleton(Ident("Foo5")), None)), List(DefDef("$lessinit$greater$default$2", Nil, List(List(ValDef("a", TypeIdent("Int"), None))), Inferred(), Some(Ident("a")))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo6", DefDef("", Nil, List(List(ValDef("a", TypeIdent("Int"), None)), List(ValDef("b", Singleton(Ident("a")), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), None), ValDef("b", Inferred(), None)))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo6", DefDef("", Nil, List(List(ValDef("a", TypeIdent("Int"), None)), List(ValDef("b", Singleton(Ident("a")), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), None), ValDef("b", Inferred(), None)))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo7", DefDef("", Nil, List(List(ValDef("a", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), None), DefDef("", Nil, List(Nil), Inferred(), Some(Block(List(Apply(Select(This(Some("Foo7")), ""), List(Literal(Constant(6))))), Literal(Constant(())))))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo7", DefDef("", Nil, List(List(ValDef("a", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), None), DefDef("", Nil, List(Nil), Inferred(), Some(Block(List(Apply(Select(This(Some("Foo7")), ""), List(Literal(Constant.Int(6))))), Literal(Constant.Unit()))))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo8", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(Apply(Ident("println"), List(Literal(Constant(0))))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo8", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(Apply(Ident("println"), List(Literal(Constant.Int(0))))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo10", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), Some(Literal(Constant(9))))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo10", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), Some(Literal(Constant.Int(9))))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo11", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), Some(Literal(Constant(10)))), DefDef("a_=", Nil, List(List(ValDef("x$1", Inferred(), None))), Inferred(), Some(Literal(Constant(()))))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo11", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), Some(Literal(Constant.Int(10)))), DefDef("a_=", Nil, List(List(ValDef("x$1", Inferred(), None))), Inferred(), Some(Literal(Constant.Unit())))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo12", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), Some(Literal(Constant(11))))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo12", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("a", Inferred(), Some(Literal(Constant.Int(11))))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, Nil), ClassDef("Bar", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(TypeIdent("Foo")), ""), Nil)), Nil, None, Nil)), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, Nil), ClassDef("Bar", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(TypeIdent("Foo")), ""), Nil)), Nil, None, Nil)), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo2", DefDef("", Nil, List(Nil), Inferred(), None), List(Inferred()), Nil, None, Nil), ClassDef("Bar", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil), TypeIdent("Foo2")), Nil, None, Nil)), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo2", DefDef("", Nil, List(Nil), Inferred(), None), List(Inferred()), Nil, None, Nil), ClassDef("Bar", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil), TypeIdent("Foo2")), Nil, None, Nil)), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(List(ValDef("i", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("i", Inferred(), None))), ClassDef("Bar", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(TypeIdent("Foo")), ""), List(Literal(Constant(1))))), Nil, None, Nil)), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(List(ValDef("i", TypeIdent("Int"), None))), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(ValDef("i", Inferred(), None))), ClassDef("Bar", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(TypeIdent("Foo")), ""), List(Literal(Constant.Int(1))))), Nil, None, Nil)), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(TypeDef("X", TypeIdent("Int")))), DefDef("f", Nil, List(List(ValDef("a", TypeIdent("Foo"), None))), TypeSelect(Ident("a"), "X"), Some(Ident("???")))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(TypeDef("X", TypeIdent("Int")))), DefDef("f", Nil, List(List(ValDef("a", TypeIdent("Foo"), None))), TypeSelect(Ident("a"), "X"), Some(Ident("???")))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(TypeDef("X", TypeBoundsTree(Inferred(), Inferred())))), DefDef("f", Nil, List(List(ValDef("a", Refined(TypeIdent("Foo"), List(TypeDef("X", TypeIdent("Int")))), None))), TypeSelect(Ident("a"), "X"), Some(Ident("???")))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ClassDef("Foo", DefDef("", Nil, List(Nil), Inferred(), None), List(Apply(Select(New(Inferred()), ""), Nil)), Nil, None, List(TypeDef("X", TypeBoundsTree(Inferred(), Inferred())))), DefDef("f", Nil, List(List(ValDef("a", Refined(TypeIdent("Foo"), List(TypeDef("X", TypeIdent("Int")))), None))), TypeSelect(Ident("a"), "X"), Some(Ident("???")))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Block(List(ValDef("lambda", Applied(Inferred(), List(TypeIdent("Int"), TypeIdent("Int"))), Some(Block(List(DefDef("$anonfun", Nil, List(List(ValDef("x", Inferred(), None))), Inferred(), Some(Ident("x")))), Closure(Ident("$anonfun"), None))))), Literal(Constant(())))) +Inlined(None, Nil, Block(List(ValDef("lambda", Applied(Inferred(), List(TypeIdent("Int"), TypeIdent("Int"))), Some(Block(List(DefDef("$anonfun", Nil, List(List(ValDef("x", Inferred(), None))), Inferred(), Some(Ident("x")))), Closure(Ident("$anonfun"), None))))), Literal(Constant.Unit()))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") diff --git a/tests/run-macros/tasty-indexed-map/quoted_1.scala b/tests/run-macros/tasty-indexed-map/quoted_1.scala index 8c0fbc8fef54..c71173f3a446 100644 --- a/tests/run-macros/tasty-indexed-map/quoted_1.scala +++ b/tests/run-macros/tasty-indexed-map/quoted_1.scala @@ -28,7 +28,7 @@ object Index { import qctx.tasty._ def name(tp: Type): String = tp match { - case ConstantType(Constant(str: String)) => str + case ConstantType(Constant.String(str)) => str } def names(tp: Type): List[String] = tp match { diff --git a/tests/run-macros/tasty-interpolation-1/Macro.scala b/tests/run-macros/tasty-interpolation-1/Macro.scala index 7d82843b563a..b594eb2db414 100644 --- a/tests/run-macros/tasty-interpolation-1/Macro.scala +++ b/tests/run-macros/tasty-interpolation-1/Macro.scala @@ -59,7 +59,7 @@ abstract class MacroStringInterpolator[T] { strCtxExpr.unseal.underlyingArgument match { case Select(Typed(Apply(_, List(Apply(_, List(Typed(Repeated(strCtxArgTrees, _), Inferred()))))), _), _) => val strCtxArgs = strCtxArgTrees.map { - case Literal(Constant(str: String)) => str + case Literal(Constant.String(str)) => str case tree => throw new NotStaticlyKnownError("Expected statically known StringContext", tree.seal) } StringContext(strCtxArgs: _*) diff --git a/tests/run-macros/tasty-macro-const/quoted_1.scala b/tests/run-macros/tasty-macro-const/quoted_1.scala index 2068f5565fde..5d21c516aafc 100644 --- a/tests/run-macros/tasty-macro-const/quoted_1.scala +++ b/tests/run-macros/tasty-macro-const/quoted_1.scala @@ -8,7 +8,7 @@ object Macros { import qctx.tasty._ val xTree: Term = x.unseal xTree match { - case Inlined(_, _, Literal(Constant(n: Int))) => + case Inlined(_, _, Literal(Constant.Int(n))) => if (n <= 0) { report.error("Parameter must be natural number") '{0} diff --git a/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala index 6d495df0cad2..47e58d92a612 100644 --- a/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala @@ -46,7 +46,7 @@ object XmlQuote { if isSCOpsConversion(conv) && isStringContextApply(fun) && values.forall(isStringConstant) => - values.collect { case Literal(Constant(value: String)) => value } + values.collect { case Literal(Constant.String(value)) => value } case tree => report.error(s"String literal expected, but ${tree.showExtractors} found") return '{ ??? } diff --git a/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala index 1a19cf143168..8666d0c2c84d 100644 --- a/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala @@ -41,7 +41,7 @@ object XmlQuote { ctx1 match { case Apply(fun, List(Typed(Repeated(values, _), _))) if isStringContextApply(fun) => values.iterator.map { - case Literal(Constant(value: String)) => value + case Literal(Constant.String(value)) => value case _ => report.error("Expected statically known String") return '{???}