From 258bb7fc29340682a55e5b8121babeb55838a236 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 30 Oct 2019 09:23:19 +0100 Subject: [PATCH 1/2] Extract modules in reflection Type This was done on Tree an all other types in TASTy reflect but we forgot to do it for Type --- community-build/community-projects/scalatest | 2 +- community-build/community-projects/shapeless | 2 +- .../tasty/reflect/ExtractorsPrinter.scala | 72 ++-- .../tasty/reflect/SourceCodePrinter.scala | 118 ++--- .../scala/tasty/reflect/TypeOrBoundsOps.scala | 405 +++++++++--------- .../tasty-macro-assert-1/quoted_1.scala | 2 +- .../tasty-macro-assert-2/quoted_1.scala | 2 +- .../tasty-constant-type/Macro_1.scala | 4 +- tests/run-macros/i5941/macro_1.scala | 4 +- tests/run-macros/i6171/Macro_1.scala | 2 +- tests/run-macros/reflect-dsl/assert_1.scala | 2 +- .../reflect-select-constructor/assert_1.scala | 2 +- .../assert_1.scala | 2 +- .../reflect-select-value-class/assert_1.scala | 2 +- tests/run-macros/tasty-definitions-1.check | 30 +- tests/run-macros/tasty-eval/quoted_1.scala | 6 +- tests/run-macros/tasty-extractors-1.check | 80 ++-- tests/run-macros/tasty-extractors-2.check | 70 +-- tests/run-macros/tasty-extractors-3.check | 44 +- tests/run-macros/tasty-extractors-types.check | 8 +- .../tasty-indexed-map/quoted_1.scala | 4 +- .../tasty-macro-assert/quoted_1.scala | 2 +- .../tasty-seal-method/quoted_1.scala | 2 +- .../tasty-simplified/quoted_1.scala | 2 +- 24 files changed, 434 insertions(+), 435 deletions(-) diff --git a/community-build/community-projects/scalatest b/community-build/community-projects/scalatest index dbc37c4d36aa..d59471cdc711 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit dbc37c4d36aa5e8b390d654fa990d51740e6734d +Subproject commit d59471cdc7112f0e2c6f4f8b32ed15b6fd6f5515 diff --git a/community-build/community-projects/shapeless b/community-build/community-projects/shapeless index 00797ac36c26..8f049cfa67de 160000 --- a/community-build/community-projects/shapeless +++ b/community-build/community-projects/shapeless @@ -1 +1 @@ -Subproject commit 00797ac36c26a88b7a67b7b0bfcc922fed0da313 +Subproject commit 8f049cfa67de9c6e6fcca11cefee4f211b3eefe3 diff --git a/library/src/scala/tasty/reflect/ExtractorsPrinter.scala b/library/src/scala/tasty/reflect/ExtractorsPrinter.scala index 895bbe198bd4..293eac1f76ef 100644 --- a/library/src/scala/tasty/reflect/ExtractorsPrinter.scala +++ b/library/src/scala/tasty/reflect/ExtractorsPrinter.scala @@ -183,43 +183,43 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val tasty: R) extends Print } def visitType(x: TypeOrBounds): Buffer = x match { - case Type.ConstantType(value) => - this += "Type.ConstantType(" += value += ")" - case Type.TermRef(qual, name) => - this += "Type.TermRef(" += qual+= ", \"" += name += "\")" - case Type.TypeRef(qual, name) => - this += "Type.TypeRef(" += qual += ", \"" += name += "\")" - case Type.Refinement(parent, name, info) => - this += "Type.Refinement(" += parent += ", " += name += ", " += info += ")" - case Type.AppliedType(tycon, args) => - this += "Type.AppliedType(" += tycon += ", " ++= args += ")" - case Type.AnnotatedType(underlying, annot) => - this += "Type.AnnotatedType(" += underlying += ", " += annot += ")" - case Type.AndType(left, right) => - this += "Type.AndType(" += left += ", " += right += ")" - case Type.OrType(left, right) => - this += "Type.OrType(" += left += ", " += right += ")" - case Type.MatchType(bound, scrutinee, cases) => - this += "Type.MatchType(" += bound += ", " += scrutinee += ", " ++= cases += ")" - case Type.ByNameType(underlying) => - this += "Type.ByNameType(" += underlying += ")" - case Type.ParamRef(binder, idx) => - this += "Type.ParamRef(" += binder += ", " += idx += ")" - case Type.ThisType(tp) => - this += "Type.ThisType(" += tp += ")" - case Type.SuperType(thistpe, supertpe) => - this += "Type.SuperType(" += thistpe += ", " += supertpe += ")" - case Type.RecursiveThis(binder) => - this += "Type.RecursiveThis(" += binder += ")" - case Type.RecursiveType(underlying) => - this += "Type.RecursiveType(" += underlying += ")" - case Type.MethodType(argNames, argTypes, resType) => - this += "Type.MethodType(" ++= argNames += ", " ++= argTypes += ", " += resType += ")" - case Type.PolyType(argNames, argBounds, resType) => - this += "Type.PolyType(" ++= argNames += ", " ++= argBounds += ", " += resType += ")" - case Type.TypeLambda(argNames, argBounds, resType) => + case ConstantType(value) => + this += "ConstantType(" += value += ")" + case TermRef(qual, name) => + this += "TermRef(" += qual+= ", \"" += name += "\")" + case TypeRef(qual, name) => + this += "TypeRef(" += qual += ", \"" += name += "\")" + case Refinement(parent, name, info) => + this += "Refinement(" += parent += ", " += name += ", " += info += ")" + case AppliedType(tycon, args) => + this += "AppliedType(" += tycon += ", " ++= args += ")" + case AnnotatedType(underlying, annot) => + this += "AnnotatedType(" += underlying += ", " += annot += ")" + case AndType(left, right) => + this += "AndType(" += left += ", " += right += ")" + case OrType(left, right) => + this += "OrType(" += left += ", " += right += ")" + case MatchType(bound, scrutinee, cases) => + this += "MatchType(" += bound += ", " += scrutinee += ", " ++= cases += ")" + case ByNameType(underlying) => + this += "ByNameType(" += underlying += ")" + case ParamRef(binder, idx) => + this += "ParamRef(" += binder += ", " += idx += ")" + case ThisType(tp) => + this += "ThisType(" += tp += ")" + case SuperType(thistpe, supertpe) => + this += "SuperType(" += thistpe += ", " += supertpe += ")" + case RecursiveThis(binder) => + this += "RecursiveThis(" += binder += ")" + case RecursiveType(underlying) => + this += "RecursiveType(" += underlying += ")" + case MethodType(argNames, argTypes, resType) => + this += "MethodType(" ++= argNames += ", " ++= argTypes += ", " += resType += ")" + case PolyType(argNames, argBounds, resType) => + this += "PolyType(" ++= argNames += ", " ++= argBounds += ", " += resType += ")" + case TypeLambda(argNames, argBounds, resType) => // resType is not printed to avoid cycles - this += "Type.TypeLambda(" ++= argNames += ", " ++= argBounds += ", _)" + this += "TypeLambda(" ++= argNames += ", " ++= argBounds += ", _)" case TypeBounds(lo, hi) => this += "TypeBounds(" += lo += ", " += hi += ")" case NoPrefix() => diff --git a/library/src/scala/tasty/reflect/SourceCodePrinter.scala b/library/src/scala/tasty/reflect/SourceCodePrinter.scala index f36720588d41..3921b8bd6c46 100644 --- a/library/src/scala/tasty/reflect/SourceCodePrinter.scala +++ b/library/src/scala/tasty/reflect/SourceCodePrinter.scala @@ -428,9 +428,9 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig printTree(term) this += (if (scala.internal.Chars.isOperatorPart(sb.last)) " : " else ": ") def printTypeOrAnnots(tpe: Type): Unit = tpe match { - case Type.AnnotatedType(tp, annot) if tp == term.tpe => + case AnnotatedType(tp, annot) if tp == term.tpe => printAnnotation(annot) - case Type.AnnotatedType(tp, annot) => + case AnnotatedType(tp, annot) => printTypeOrAnnots(tp) this += " " printAnnotation(annot) @@ -964,20 +964,20 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig case Inferred() => // TODO try to move this logic into `printType` def printTypeAndAnnots(tpe: Type): Buffer = tpe match { - case Type.AnnotatedType(tp, annot) => + case AnnotatedType(tp, annot) => printTypeAndAnnots(tp) this += " " printAnnotation(annot) - case Type.IsTypeRef(tpe) if tpe.typeSymbol.fullName == "scala.runtime.Null$" || tpe.typeSymbol.fullName == "scala.runtime.Nothing$" => + case IsTypeRef(tpe) if tpe.typeSymbol.fullName == "scala.runtime.Null$" || tpe.typeSymbol.fullName == "scala.runtime.Nothing$" => // scala.runtime.Null$ and scala.runtime.Nothing$ are not modules, those are their actual names printType(tpe) - case Type.IsTermRef(tpe) if tpe.termSymbol.isClassDef && tpe.termSymbol.name.endsWith("$") => + case IsTermRef(tpe) if tpe.termSymbol.isClassDef && tpe.termSymbol.name.endsWith("$") => printType(tpe) this += ".type" - case Type.IsTypeRef(tpe) if tpe.typeSymbol.isClassDef && tpe.typeSymbol.name.endsWith("$") => + case IsTypeRef(tpe) if tpe.typeSymbol.isClassDef && tpe.typeSymbol.name.endsWith("$") => printType(tpe) this += ".type" - case tpe @ Type.TermRef(sym, _) => + case tpe @ TermRef(sym, _) => printType(tpe) this += ".type" case tpe => printType(tpe) @@ -1064,13 +1064,13 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig * prefix `C.this` to avoid type checking errors. */ def printType(tpe: Type)(given elideThis: Option[Symbol] = None): Buffer = tpe match { - case Type.ConstantType(const) => + case ConstantType(const) => printConstant(const) - case Type.IsTypeRef(tpe) => + case IsTypeRef(tpe) => val sym = tpe.typeSymbol tpe.qualifier match { - case Type.ThisType(tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass => + case ThisType(tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass => case NoPrefix() => if (sym.owner.flags.is(Flags.Package)) { // TODO should these be in the prefix? These are at least `scala`, `java` and `scala.collection`. @@ -1078,25 +1078,25 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig if (packagePath != "") this += packagePath += "." } - case Type.IsTermRef(prefix) if prefix.termSymbol.isClassDef => + case IsTermRef(prefix) if prefix.termSymbol.isClassDef => printType(prefix) this += "#" - case Type.IsTypeRef(prefix) if prefix.typeSymbol.isClassDef => + case IsTypeRef(prefix) if prefix.typeSymbol.isClassDef => printType(prefix) this += "#" - case IsType(Type.ThisType(Type.TermRef(cdef, _))) if elideThis.nonEmpty && cdef == elideThis.get => - case IsType(Type.ThisType(Type.TypeRef(cdef, _))) if elideThis.nonEmpty && cdef == elideThis.get => + case IsType(ThisType(TermRef(cdef, _))) if elideThis.nonEmpty && cdef == elideThis.get => + case IsType(ThisType(TypeRef(cdef, _))) if elideThis.nonEmpty && cdef == elideThis.get => case IsType(prefix) => printType(prefix) this += "." } this += highlightTypeDef(sym.name.stripSuffix("$")) - case Type.TermRef(prefix, name) => + case TermRef(prefix, name) => prefix match { case NoPrefix() => this += highlightTypeDef(name) - case Type.ThisType(tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass => + case ThisType(tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass => this += highlightTypeDef(name) case _ => printTypeOrBound(prefix) @@ -1105,54 +1105,54 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig this } - case tpe @ Type.Refinement(_, _, _) => + case tpe @ Refinement(_, _, _) => printRefinement(tpe) - case Type.AppliedType(tp, args) => + case AppliedType(tp, args) => tp match { - case Type.IsTypeLambda(tp) => + case IsTypeLambda(tp) => printType(tpe.dealias) - case Type.TypeRef(Types.ScalaPackage(), "") => + case TypeRef(Types.ScalaPackage(), "") => this += "_*" case _ => printType(tp) inSquare(printTypesOrBounds(args, ", ")) } - case Type.AnnotatedType(tp, annot) => + case AnnotatedType(tp, annot) => val Annotation(ref, args) = annot printType(tp) this += " " printAnnotation(annot) - case Type.AndType(left, right) => + case AndType(left, right) => printType(left) this += highlightTypeDef(" & ") printType(right) - case Type.OrType(left, right) => + case OrType(left, right) => printType(left) this += highlightTypeDef(" | ") printType(right) - case Type.MatchType(bound, scrutinee, cases) => + case MatchType(bound, scrutinee, cases) => printType(scrutinee) this += highlightKeyword(" match ") inBlock(printTypes(cases, lineBreak())) - case Type.ByNameType(tp) => + case ByNameType(tp) => this += highlightTypeDef(" => ") printType(tp) - case Type.ThisType(tp) => + case ThisType(tp) => tp match { - case Type.IsTypeRef(tp) if !tp.typeSymbol.flags.is(Flags.Object) => + case IsTypeRef(tp) if !tp.typeSymbol.flags.is(Flags.Object) => printFullClassName(tp) this += highlightTypeDef(".this") - case Type.TypeRef(prefix, name) if name.endsWith("$") => + case TypeRef(prefix, name) if name.endsWith("$") => prefix match { case NoPrefix() => - case Type.ThisType(tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass => + case ThisType(tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass => case _ => printTypeOrBound(prefix) this += "." @@ -1162,43 +1162,43 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig printType(tp) } - case Type.SuperType(thistpe, supertpe) => + case SuperType(thistpe, supertpe) => printType(supertpe) this += highlightTypeDef(".super") - case Type.TypeLambda(paramNames, tparams, body) => + case TypeLambda(paramNames, tparams, body) => inSquare(printMethodicTypeParams(paramNames, tparams)) this += highlightTypeDef(" => ") printTypeOrBound(body) - case Type.ParamRef(lambda, idx) => + case ParamRef(lambda, idx) => lambda match { - case Type.MethodType(params, _, _) => this += params(idx) - case Type.PolyType(params, _, _) => this += params(idx) - case Type.TypeLambda(params, _, _) => this += params(idx) + case MethodType(params, _, _) => this += params(idx) + case PolyType(params, _, _) => this += params(idx) + case TypeLambda(params, _, _) => this += params(idx) } - case Type.RecursiveType(tpe) => + case RecursiveType(tpe) => printType(tpe) - case Type.RecursiveThis(_) => + case RecursiveThis(_) => this += highlightTypeDef("this") - case Type.IsMethodType(tpe) => + case IsMethodType(tpe) => this += "(" printList(tpe.paramNames.zip(tpe.paramTypes), ", ", (x: (String, Type)) => (this += x._1 += ": ").printType(x._2)) this += ")" printType(tpe.resType) - case Type.IsPolyType(tpe) => + case IsPolyType(tpe) => this += "[" printList(tpe.paramNames.zip(tpe.paramBounds), ", ", (x: (String, TypeBounds)) => (this += x._1 += " ").printTypeOrBound(x._2)) this += "]" printType(tpe.resType) - case Type.IsTypeLambda(tpe) => + case IsTypeLambda(tpe) => this += "[" printList(tpe.paramNames.zip(tpe.paramBounds), ", ", (x: (String, TypeBounds)) => (this += x._1 += " ").printTypeOrBound(x._2)) @@ -1240,9 +1240,9 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig val annots = definition.symbol.annots.filter { case Annotation(annot, _) => annot.tpe match { - case Type.TypeRef(Type.IsTermRef(prefix), _) if prefix.termSymbol.fullName == "scala.annotation.internal" => false - case Type.TypeRef(Type.IsTypeRef(prefix), _) if prefix.typeSymbol.fullName == "scala.annotation.internal" => false - case Type.TypeRef(Types.ScalaPackage(), "forceInline") => false + case TypeRef(IsTermRef(prefix), _) if prefix.termSymbol.fullName == "scala.annotation.internal" => false + case TypeRef(IsTypeRef(prefix), _) if prefix.typeSymbol.fullName == "scala.annotation.internal" => false + case TypeRef(Types.ScalaPackage(), "forceInline") => false case _ => true } case x => throw new MatchError(x.showExtractors) @@ -1254,13 +1254,13 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig def printRefinement(tpe: Type)(given elideThis: Option[Symbol]): Buffer = { def printMethodicType(tp: TypeOrBounds): Unit = tp match { - case tp @ Type.MethodType(paramNames, params, res) => + case tp @ MethodType(paramNames, params, res) => inParens(printMethodicTypeParams(paramNames, params)) printMethodicType(res) - case tp @ Type.TypeLambda(paramNames, params, res) => + case tp @ TypeLambda(paramNames, params, res) => inSquare(printMethodicTypeParams(paramNames, params)) printMethodicType(res) - case Type.ByNameType(t) => + case ByNameType(t) => this += ": " printType(t) case IsType(tp) => @@ -1268,7 +1268,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig printType(tp) } def rec(tp: Type): Unit = tp match { - case Type.Refinement(parent, name, info) => + case Refinement(parent, name, info) => rec(parent) indented { this += lineBreak() @@ -1276,7 +1276,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig case IsTypeBounds(info) => this += highlightKeyword("type ") += highlightTypeDef(name) printBounds(info) - case Type.ByNameType(_) | Type.MethodType(_, _, _) | Type.TypeLambda(_, _, _) => + case ByNameType(_) | MethodType(_, _, _) | TypeLambda(_, _, _) => this += highlightKeyword("def ") += highlightTypeDef(name) printMethodicType(info) case IsType(info) => @@ -1338,7 +1338,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig def printProtectedOrPrivate(definition: Definition): Boolean = { var prefixWasPrinted = false def printWithin(within: Type) = within match { - case Type.TypeRef(_, name) => this += name + case TypeRef(_, name) => this += name case _ => printFullClassName(within) } if (definition.symbol.flags.is(Flags.Protected)) { @@ -1365,12 +1365,12 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig def printFullClassName(tp: TypeOrBounds): Unit = { def printClassPrefix(prefix: TypeOrBounds): Unit = prefix match { - case Type.TypeRef(prefix2, name) => + case TypeRef(prefix2, name) => printClassPrefix(prefix2) this += name += "." case _ => } - val Type.TypeRef(prefix, name) = tp + val TypeRef(prefix, name) = tp printClassPrefix(prefix) this += name } @@ -1412,7 +1412,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig def unapply(arg: Tree)(given ctx: Context): Option[(String, List[Term])] = arg match { case IsTerm(arg @ Apply(fn, args)) => fn.tpe match { - case tpe @ Type.TermRef(Type.ThisType(Type.TypeRef(_, name)), name2) if name == "" => + case tpe @ TermRef(ThisType(TypeRef(_, name)), name2) if name == "" => Some((name2, args)) case _ => None } @@ -1434,37 +1434,37 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig object JavaLangObject { def unapply(tpe: Type)(given ctx: Context): Boolean = tpe match { - case Type.TypeRef(Type.IsTermRef(prefix), "Object") => prefix.typeSymbol.fullName == "java.lang" + case TypeRef(IsTermRef(prefix), "Object") => prefix.typeSymbol.fullName == "java.lang" case _ => false } } object Sequence { def unapply(tpe: Type)(given ctx: Context): Option[Type] = tpe match { - case Type.AppliedType(Type.TypeRef(Type.IsTermRef(prefix), "Seq"), IsType(tp) :: Nil) if prefix.termSymbol.fullName == "scala.collection" => Some(tp) - case Type.AppliedType(Type.TypeRef(Type.IsTypeRef(prefix), "Seq"), IsType(tp) :: Nil) if prefix.typeSymbol.fullName == "scala.collection" => Some(tp) + case AppliedType(TypeRef(IsTermRef(prefix), "Seq"), IsType(tp) :: Nil) if prefix.termSymbol.fullName == "scala.collection" => Some(tp) + case AppliedType(TypeRef(IsTypeRef(prefix), "Seq"), IsType(tp) :: Nil) if prefix.typeSymbol.fullName == "scala.collection" => Some(tp) case _ => None } } object RepeatedAnnotation { def unapply(tpe: Type)(given ctx: Context): Boolean = tpe match { - case Type.TypeRef(Type.IsTermRef(prefix), "Repeated") => prefix.termSymbol.fullName == "scala.annotation.internal" - case Type.TypeRef(Type.IsTypeRef(prefix), "Repeated") => prefix.typeSymbol.fullName == "scala.annotation.internal" + case TypeRef(IsTermRef(prefix), "Repeated") => prefix.termSymbol.fullName == "scala.annotation.internal" + case TypeRef(IsTypeRef(prefix), "Repeated") => prefix.typeSymbol.fullName == "scala.annotation.internal" case _ => false } } object Repeated { def unapply(tpe: Type)(given ctx: Context): Option[Type] = tpe match { - case Type.AppliedType(Type.TypeRef(ScalaPackage(), ""), IsType(tp) :: Nil) => Some(tp) + case AppliedType(TypeRef(ScalaPackage(), ""), IsType(tp) :: Nil) => Some(tp) case _ => None } } object ScalaPackage { def unapply(tpe: TypeOrBounds)(given ctx: Context): Boolean = tpe match { - case Type.IsTermRef(tpe) => tpe.termSymbol == defn.ScalaPackage + case IsTermRef(tpe) => tpe.termSymbol == defn.ScalaPackage case _ => false } } diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala index 032418ed6925..057dd6ff60eb 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala @@ -69,211 +69,210 @@ trait TypeOrBoundsOps extends Core { } object Type { + def apply(clazz: Class[_])(given ctx: Context): Type = + internal.Type_apply(clazz) + } + + object IsConstantType { + /** Matches any ConstantType and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[ConstantType] = + internal.matchConstantType(tpe) + } + + object ConstantType { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[Constant] = + internal.matchConstantType(typeOrBounds).map(_.constant) + } + + object IsTermRef { + /** Matches any TermRef and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[TermRef] = + internal.matchTermRef(tpe) + } + + object TermRef { + def apply(qual: TypeOrBounds, name: String)(given ctx: Context): TermRef = + internal.TermRef_apply(qual, name) + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(TypeOrBounds /* Type | NoPrefix */, String)] = + internal.matchTermRef(typeOrBounds).map(x => (x.qualifier, x.name)) + } + + object IsTypeRef { + /** Matches any TypeRef and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[TypeRef] = + internal.matchTypeRef(tpe) + } + + object TypeRef { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(TypeOrBounds /* Type | NoPrefix */, String)] = + internal.matchTypeRef(typeOrBounds).map(x => (x.qualifier, x.name)) + } + + object IsSuperType { + /** Matches any SuperType and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[SuperType] = + internal.matchSuperType(tpe) + } + + object SuperType { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Type)] = + internal.matchSuperType(typeOrBounds).map(x => (x.thistpe, x.supertpe)) + } + + object IsRefinement { + /** Matches any Refinement and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[Refinement] = + internal.matchRefinement(tpe) + } + + object Refinement { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, String, TypeOrBounds /* Type | TypeBounds */)] = + internal.matchRefinement(typeOrBounds).map(x => (x.parent, x.name, x.info)) + } + + object IsAppliedType { + /** Matches any AppliedType and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[AppliedType] = + internal.matchAppliedType(tpe) + } + + object AppliedType { + def apply(tycon: Type, args: List[TypeOrBounds])(given ctx: Context) : AppliedType = + internal.AppliedType_apply(tycon, args) + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, List[TypeOrBounds /* Type | TypeBounds */])] = + internal.matchAppliedType(typeOrBounds).map(x => (x.tycon, x.args)) + } + + object IsAnnotatedType { + /** Matches any AnnotatedType and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[AnnotatedType] = + internal.matchAnnotatedType(tpe) + } + + object AnnotatedType { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Term)] = + internal.matchAnnotatedType(typeOrBounds).map(x => (x.underlying, x.annot)) + } + + object IsAndType { + /** Matches any AndType and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[AndType] = + internal.matchAndType(tpe) + } + + object AndType { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Type)] = + internal.matchAndType(typeOrBounds).map(x => (x.left, x.right)) + } + + object IsOrType { + /** Matches any OrType and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[OrType] = + internal.matchOrType(tpe) + } + + object OrType { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Type)] = + internal.matchOrType(typeOrBounds).map(x => (x.left, x.right)) + } + + object IsMatchType { + /** Matches any MatchType and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[MatchType] = + internal.matchMatchType(tpe) + } + + object MatchType { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Type, List[Type])] = + internal.matchMatchType(typeOrBounds).map(x => (x.bound, x.scrutinee, x.cases)) + } + + object IsByNameType { + /** Matches any ByNameType and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[ByNameType] = + internal.matchByNameType(tpe) + } + + object ByNameType { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[Type] = + internal.matchByNameType(typeOrBounds).map(_.underlying) + } + + object IsParamRef { + /** Matches any ParamRef and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[ParamRef] = + internal.matchParamRef(tpe) + } + + object ParamRef { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(LambdaType[TypeOrBounds], Int)] = + internal.matchParamRef(typeOrBounds).map(x => (x.binder, x.paramNum)) + } + + object IsThisType { + /** Matches any ThisType and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[ThisType] = + internal.matchThisType(tpe) + } + + object ThisType { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[Type] = + internal.matchThisType(typeOrBounds).map(_.tref) + } + + object IsRecursiveThis { + /** Matches any RecursiveThis and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[RecursiveThis] = + internal.matchRecursiveThis(tpe) + } + + object RecursiveThis { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[RecursiveType] = + internal.matchRecursiveThis(typeOrBounds).map(_.binder) + } + + object IsRecursiveType { + /** Matches any RecursiveType and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[RecursiveType] = + internal.matchRecursiveType(tpe) + } + + object RecursiveType { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[Type] = + internal.matchRecursiveType(typeOrBounds).map(_.underlying) + } - def apply(clazz: Class[_])(given ctx: Context): Type = internal.Type_apply(clazz) - - object IsConstantType { - /** Matches any ConstantType and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[ConstantType] = - internal.matchConstantType(tpe) - } - - object ConstantType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[Constant] = - internal.matchConstantType(typeOrBounds).map(_.constant) - } - - object IsTermRef { - /** Matches any TermRef and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[TermRef] = - internal.matchTermRef(tpe) - } - - object TermRef { - def apply(qual: TypeOrBounds, name: String)(given ctx: Context): TermRef = - internal.TermRef_apply(qual, name) - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(TypeOrBounds /* Type | NoPrefix */, String)] = - internal.matchTermRef(typeOrBounds).map(x => (x.qualifier, x.name)) - } - - object IsTypeRef { - /** Matches any TypeRef and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[TypeRef] = - internal.matchTypeRef(tpe) - } - - object TypeRef { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(TypeOrBounds /* Type | NoPrefix */, String)] = - internal.matchTypeRef(typeOrBounds).map(x => (x.qualifier, x.name)) - } - - object IsSuperType { - /** Matches any SuperType and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[SuperType] = - internal.matchSuperType(tpe) - } - - object SuperType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Type)] = - internal.matchSuperType(typeOrBounds).map(x => (x.thistpe, x.supertpe)) - } - - object IsRefinement { - /** Matches any Refinement and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[Refinement] = - internal.matchRefinement(tpe) - } - - object Refinement { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, String, TypeOrBounds /* Type | TypeBounds */)] = - internal.matchRefinement(typeOrBounds).map(x => (x.parent, x.name, x.info)) - } - - object IsAppliedType { - /** Matches any AppliedType and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[AppliedType] = - internal.matchAppliedType(tpe) - } - - object AppliedType { - def apply(tycon: Type, args: List[TypeOrBounds])(given ctx: Context) : AppliedType = - internal.AppliedType_apply(tycon, args) - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, List[TypeOrBounds /* Type | TypeBounds */])] = - internal.matchAppliedType(typeOrBounds).map(x => (x.tycon, x.args)) - } - - object IsAnnotatedType { - /** Matches any AnnotatedType and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[AnnotatedType] = - internal.matchAnnotatedType(tpe) - } - - object AnnotatedType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Term)] = - internal.matchAnnotatedType(typeOrBounds).map(x => (x.underlying, x.annot)) - } - - object IsAndType { - /** Matches any AndType and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[AndType] = - internal.matchAndType(tpe) - } - - object AndType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Type)] = - internal.matchAndType(typeOrBounds).map(x => (x.left, x.right)) - } - - object IsOrType { - /** Matches any OrType and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[OrType] = - internal.matchOrType(tpe) - } - - object OrType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Type)] = - internal.matchOrType(typeOrBounds).map(x => (x.left, x.right)) - } - - object IsMatchType { - /** Matches any MatchType and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[MatchType] = - internal.matchMatchType(tpe) - } - - object MatchType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Type, List[Type])] = - internal.matchMatchType(typeOrBounds).map(x => (x.bound, x.scrutinee, x.cases)) - } - - object IsByNameType { - /** Matches any ByNameType and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[ByNameType] = - internal.matchByNameType(tpe) - } - - object ByNameType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[Type] = - internal.matchByNameType(typeOrBounds).map(_.underlying) - } - - object IsParamRef { - /** Matches any ParamRef and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[ParamRef] = - internal.matchParamRef(tpe) - } - - object ParamRef { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(LambdaType[TypeOrBounds], Int)] = - internal.matchParamRef(typeOrBounds).map(x => (x.binder, x.paramNum)) - } - - object IsThisType { - /** Matches any ThisType and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[ThisType] = - internal.matchThisType(tpe) - } - - object ThisType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[Type] = - internal.matchThisType(typeOrBounds).map(_.tref) - } - - object IsRecursiveThis { - /** Matches any RecursiveThis and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[RecursiveThis] = - internal.matchRecursiveThis(tpe) - } - - object RecursiveThis { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[RecursiveType] = - internal.matchRecursiveThis(typeOrBounds).map(_.binder) - } - - object IsRecursiveType { - /** Matches any RecursiveType and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[RecursiveType] = - internal.matchRecursiveType(tpe) - } - - object RecursiveType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[Type] = - internal.matchRecursiveType(typeOrBounds).map(_.underlying) - } - - object IsMethodType { - /** Matches any MethodType and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[MethodType] = - internal.matchMethodType(tpe) - } - - object MethodType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(List[String], List[Type], Type)] = - internal.matchMethodType(typeOrBounds).map(x => (x.paramNames, x.paramTypes, x.resType)) - } - - object IsPolyType { - /** Matches any PolyType and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[PolyType] = - internal.matchPolyType(tpe) - } - - object PolyType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(List[String], List[TypeBounds], Type)] = - internal.matchPolyType(typeOrBounds).map(x => (x.paramNames, x.paramBounds, x.resType)) - } - - object IsTypeLambda { - /** Matches any TypeLambda and returns it */ - def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[TypeLambda] = - internal.matchTypeLambda(tpe) - } - - object TypeLambda { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(List[String], List[TypeBounds], Type)] = - internal.matchTypeLambda(typeOrBounds).map(x => (x.paramNames, x.paramBounds, x.resType)) - } + object IsMethodType { + /** Matches any MethodType and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[MethodType] = + internal.matchMethodType(tpe) + } + + object MethodType { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(List[String], List[Type], Type)] = + internal.matchMethodType(typeOrBounds).map(x => (x.paramNames, x.paramTypes, x.resType)) + } + + object IsPolyType { + /** Matches any PolyType and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[PolyType] = + internal.matchPolyType(tpe) + } + + object PolyType { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(List[String], List[TypeBounds], Type)] = + internal.matchPolyType(typeOrBounds).map(x => (x.paramNames, x.paramBounds, x.resType)) + } + + object IsTypeLambda { + /** Matches any TypeLambda and returns it */ + def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[TypeLambda] = + internal.matchTypeLambda(tpe) + } + object TypeLambda { + def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(List[String], List[TypeBounds], Type)] = + internal.matchTypeLambda(typeOrBounds).map(x => (x.paramNames, x.paramBounds, x.resType)) } given (self: ConstantType) { diff --git a/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala b/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala index 2dd494550bf9..5f5e5c31f6ee 100644 --- a/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala +++ b/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala @@ -18,7 +18,7 @@ object Asserts { val tree = cond.unseal def isOps(tpe: TypeOrBounds): Boolean = tpe match { - case Type.IsTermRef(tpe) => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts + case IsTermRef(tpe) => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts case _ => false } diff --git a/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala b/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala index 9acb12908090..6e16d67cf112 100644 --- a/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala +++ b/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala @@ -18,7 +18,7 @@ object Asserts { val tree = cond.unseal def isOps(tpe: TypeOrBounds): Boolean = tpe match { - case Type.IsTermRef(tpe) => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts + case IsTermRef(tpe) => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts case _ => false } diff --git a/tests/pos-macros/tasty-constant-type/Macro_1.scala b/tests/pos-macros/tasty-constant-type/Macro_1.scala index e78f61ce7ca8..8ffb982667c9 100644 --- a/tests/pos-macros/tasty-constant-type/Macro_1.scala +++ b/tests/pos-macros/tasty-constant-type/Macro_1.scala @@ -9,8 +9,8 @@ object Macro { def impl[A <: Int : Type, B <: Int : Type](a: Type[A], b: Type[B])(given qctx: QuoteContext): Expr[AddInt[A, B]] = { import qctx.tasty.{_, given} - val Type.ConstantType(Constant(v1: Int)) = a.unseal.tpe - val Type.ConstantType(Constant(v2: Int)) = b.unseal.tpe + val ConstantType(Constant(v1: Int)) = a.unseal.tpe + val ConstantType(Constant(v2: Int)) = b.unseal.tpe val t = Literal(Constant((v1 + v2): Int)).tpe.seal diff --git a/tests/run-macros/i5941/macro_1.scala b/tests/run-macros/i5941/macro_1.scala index ff41ce1a77ab..44caac2cc43f 100644 --- a/tests/run-macros/i5941/macro_1.scala +++ b/tests/run-macros/i5941/macro_1.scala @@ -102,7 +102,7 @@ object Iso { val cls = tpS.classSymbol.get val companion = tpS match { - case Type.TypeRef(prefix, name) => Type.TermRef(prefix, name) + case TypeRef(prefix, name) => TermRef(prefix, name) } if (cls.caseFields.size != 1) { @@ -144,7 +144,7 @@ object Iso { } val companion = tpS match { - case Type.TypeRef(prefix, name) => Type.TermRef(prefix, name) + case TypeRef(prefix, name) => TermRef(prefix, name) } val obj = Select.overloaded(Ident(companion), "apply", Nil, Nil).seal.cast[S] diff --git a/tests/run-macros/i6171/Macro_1.scala b/tests/run-macros/i6171/Macro_1.scala index 729acd0d5d59..7a64dd649f78 100644 --- a/tests/run-macros/i6171/Macro_1.scala +++ b/tests/run-macros/i6171/Macro_1.scala @@ -9,7 +9,7 @@ object scalatest { import util._ def isImplicitMethodType(tp: Type): Boolean = - Type.IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty + IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty cond.unseal.underlyingArgument match { case t @ Apply(Select(lhs, op), rhs :: Nil) => let(lhs) { left => diff --git a/tests/run-macros/reflect-dsl/assert_1.scala b/tests/run-macros/reflect-dsl/assert_1.scala index d063cf16d1e8..7d00825d1025 100644 --- a/tests/run-macros/reflect-dsl/assert_1.scala +++ b/tests/run-macros/reflect-dsl/assert_1.scala @@ -9,7 +9,7 @@ object scalatest { import util._ def isImplicitMethodType(tp: Type): Boolean = - Type.IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty + IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty cond.unseal.underlyingArgument match { case t @ Apply(sel @ Select(lhs, op), rhs :: Nil) => diff --git a/tests/run-macros/reflect-select-constructor/assert_1.scala b/tests/run-macros/reflect-select-constructor/assert_1.scala index 0177198e6aef..fb5e8b70e619 100644 --- a/tests/run-macros/reflect-select-constructor/assert_1.scala +++ b/tests/run-macros/reflect-select-constructor/assert_1.scala @@ -9,7 +9,7 @@ object scalatest { import util._ def isImplicitMethodType(tp: Type): Boolean = - Type.IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty + IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty cond.unseal.underlyingArgument match { case t @ Apply(Select(lhs, op), rhs :: Nil) => diff --git a/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala b/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala index a6de05000b75..028788c865ad 100644 --- a/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala +++ b/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala @@ -9,7 +9,7 @@ object scalatest { import util._ def isImplicitMethodType(tp: Type): Boolean = - Type.IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty + IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty cond.unseal.underlyingArgument match { case t @ Apply(sel @ Select(lhs, op), rhs :: Nil) => diff --git a/tests/run-macros/reflect-select-value-class/assert_1.scala b/tests/run-macros/reflect-select-value-class/assert_1.scala index 0177198e6aef..fb5e8b70e619 100644 --- a/tests/run-macros/reflect-select-value-class/assert_1.scala +++ b/tests/run-macros/reflect-select-value-class/assert_1.scala @@ -9,7 +9,7 @@ object scalatest { import util._ def isImplicitMethodType(tp: Type): Boolean = - Type.IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty + IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty cond.unseal.underlyingArgument match { case t @ Apply(Select(lhs, op), rhs :: Nil) => diff --git a/tests/run-macros/tasty-definitions-1.check b/tests/run-macros/tasty-definitions-1.check index 11f76dc91eef..d16dd6d1796f 100644 --- a/tests/run-macros/tasty-definitions-1.check +++ b/tests/run-macros/tasty-definitions-1.check @@ -155,18 +155,18 @@ Tuple21 Tuple22 List(Unit, Boolean, Byte, Short, Int, Long, Float, Double, Char) List(Byte, Short, Int, Long, Float, Double, Char) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Byte") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Char") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Int") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Long") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Float") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Double") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Boolean") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Any") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "AnyVal") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "AnyRef") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "lang")), "Object") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Nothing") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Null") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "lang")), "String") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Byte") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Char") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Int") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Long") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Float") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Double") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Boolean") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "AnyVal") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "AnyRef") +TypeRef(ThisType(TypeRef(NoPrefix(), "lang")), "Object") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Nothing") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Null") +TypeRef(ThisType(TypeRef(NoPrefix(), "lang")), "String") diff --git a/tests/run-macros/tasty-eval/quoted_1.scala b/tests/run-macros/tasty-eval/quoted_1.scala index e639602a6600..25c26026b850 100644 --- a/tests/run-macros/tasty-eval/quoted_1.scala +++ b/tests/run-macros/tasty-eval/quoted_1.scala @@ -21,13 +21,13 @@ object Macros { import qctx.tasty.{_, given} e.unseal.tpe match { - case Type.IsTermRef(pre) if pre.termSymbol.isValDef => + case IsTermRef(pre) if pre.termSymbol.isValDef => val IsValDef(t) = pre.termSymbol.tree t.tpt.tpe match { - case Type.ConstantType(Constant(i: Int)) => Some(i) + case ConstantType(Constant(i: Int)) => Some(i) case _ => None } - case Type.ConstantType(Constant(i: Int)) => Some(i) + case ConstantType(Constant(i: Int)) => Some(i) case _ => None } } diff --git a/tests/run-macros/tasty-extractors-1.check b/tests/run-macros/tasty-extractors-1.check index 864c5103bcfb..d239fffd4f2e 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))) -Type.ConstantType(Constant(true)) +ConstantType(Constant(true)) Inlined(None, Nil, Literal(Constant(1))) -Type.ConstantType(Constant(1)) +ConstantType(Constant(1)) Inlined(None, Nil, Literal(Constant(2L))) -Type.ConstantType(Constant(2L)) +ConstantType(Constant(2L)) Inlined(None, Nil, Literal(Constant(2.1f))) -Type.ConstantType(Constant(2.1f)) +ConstantType(Constant(2.1f)) Inlined(None, Nil, Literal(Constant(2.2d))) -Type.ConstantType(Constant(2.2d)) +ConstantType(Constant(2.2d)) Inlined(None, Nil, Literal(Constant("abc"))) -Type.ConstantType(Constant("abc")) +ConstantType(Constant("abc")) Inlined(None, Nil, Apply(Ident("println"), List(Literal(Constant("abc"))))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Typed(Literal(Constant(8)), TypeIdent("Int"))) -Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Int") +TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int") Inlined(None, Nil, Typed(Literal(Constant(8: Byte)), TypeIdent("Byte"))) -Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Byte") +TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Byte") Inlined(None, Nil, Typed(Literal(Constant(8: Short)), TypeIdent("Short"))) -Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Short") +TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Short") Inlined(None, Nil, Literal(Constant('a'))) -Type.ConstantType(Constant('a')) +ConstantType(Constant('a')) Inlined(None, Nil, Block(List(Literal(Constant(1)), Literal(Constant(2))), Literal(Constant(3)))) -Type.ConstantType(Constant(3)) +ConstantType(Constant(3)) Inlined(None, Nil, If(Typed(Literal(Constant(true)), TypeIdent("Boolean")), Literal(Constant(1)), Literal(Constant(2)))) -Type.OrType(Type.ConstantType(Constant(1)), Type.ConstantType(Constant(2))) +OrType(ConstantType(Constant(1)), ConstantType(Constant(2))) Inlined(None, Nil, Match(Literal(Constant("a")), List(CaseDef(Literal(Constant("a")), None, Block(Nil, Literal(Constant(()))))))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Match(Literal(Constant("b")), List(CaseDef(Bind("n", Ident("_")), None, Block(Nil, Literal(Constant(()))))))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(()))))))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Match(Literal(Constant("e")), List(CaseDef(Ident("_"), None, Block(Nil, Literal(Constant(()))))))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(()))))))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(()))))))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(()))))))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))))))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(()))))))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Try(Literal(Constant(1)), List(CaseDef(Ident("_"), None, Block(Nil, Literal(Constant(()))))), None)) -Type.OrType(Type.ConstantType(Constant(1)), Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit")) +OrType(ConstantType(Constant(1)), TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit")) Inlined(None, Nil, Try(Literal(Constant(2)), Nil, Some(Literal(Constant(()))))) -Type.ConstantType(Constant(2)) +ConstantType(Constant(2)) Inlined(None, Nil, Try(Literal(Constant(3)), List(CaseDef(Ident("_"), None, Block(Nil, Literal(Constant(()))))), Some(Literal(Constant(()))))) -Type.OrType(Type.ConstantType(Constant(3)), Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit")) +OrType(ConstantType(Constant(3)), TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit")) Inlined(None, Nil, Apply(Select(Literal(Constant("a")), "=="), List(Literal(Constant("b"))))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Boolean") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Boolean") Inlined(None, Nil, Apply(Select(New(TypeIdent("Object")), ""), Nil)) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "lang")), "Object") +TypeRef(ThisType(TypeRef(NoPrefix(), "lang")), "Object") Inlined(None, Nil, Apply(Select(Ident("Int"), "box"), List(NamedArg("x", Literal(Constant(9)))))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "lang")), "Integer") +TypeRef(ThisType(TypeRef(NoPrefix(), "lang")), "Integer") Inlined(None, Nil, Apply(TypeApply(Select(Ident("Ordering"), "apply"), List(TypeIdent("Int"))), List(Ident("Int")))) -Type.AppliedType(Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "math")), "Ordering"), List(Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Block(List(ValDef("b", TypeIdent("Int"), Some(Literal(Constant(3))))), Literal(Constant(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Block(List(DefDef("f1", Nil, Nil, TypeIdent("Int"), Some(Literal(Constant(3))))), Literal(Constant(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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()))))) -Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Int") +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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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 70096a223fca..78dc659e8e8a 100644 --- a/tests/run-macros/tasty-extractors-2.check +++ b/tests/run-macros/tasty-extractors-2.check @@ -1,105 +1,105 @@ Inlined(None, Nil, Block(List(ValDef("x", Inferred(), Some(Literal(Constant(1))))), Assign(Ident("x"), Literal(Constant(2))))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") +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))) -Type.AppliedType(Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Function1"), List(Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Int"), Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Int"))) +AppliedType(TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Function1"), List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int"), TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int"))) Inlined(None, Nil, Ident("???")) -Type.TermRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Predef"), "???") +TermRef(TermRef(ThisType(TypeRef(NoPrefix(), "scala")), "Predef"), "???") Inlined(None, Nil, Literal(Constant(1))) -Type.ConstantType(Constant(1)) +ConstantType(Constant(1)) Inlined(None, Nil, Typed(Literal(Constant(1)), TypeIdent("Int"))) -Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Int") +TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int") Inlined(None, Nil, Typed(Ident("Nil"), Applied(TypeIdent("List"), List(TypeIdent("Int"))))) -Type.AppliedType(Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "immutable")), "List"), List(Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Int"))) +AppliedType(TypeRef(ThisType(TypeRef(NoPrefix(), "immutable")), "List"), List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int"))) Inlined(None, Nil, Typed(Apply(Select(New(TypeIdent("Baz")), ""), Nil), Applied(TypeIdent("&"), List(TypeIdent("Foo"), TypeIdent("Bar"))))) -Type.AndType(Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "Foo"), Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "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"))))) -Type.OrType(Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Int"), Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Predef"), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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), TypeSelect(Select(Ident("_root_"), "scala"), "Serializable")), Nil, Some(ValDef("_", Singleton(Ident("Foo")), None)), Nil)), Literal(Constant(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Block(List(TypeDef("Foo", TypeBoundsTree(Inferred(), Inferred()))), Literal(Constant(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Block(List(TypeDef("Foo", TypeIdent("Int"))), Literal(Constant(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Block(List(TypeDef("Foo", TypeBoundsTree(TypeIdent("Null"), TypeIdent("Object")))), Literal(Constant(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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())), TypeSelect(Select(Ident("_root_"), "scala"), "Serializable")), 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))), Inferred(), Some(Literal(Constant(true))))))), Literal(Constant(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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), TypeSelect(Select(Ident("_root_"), "scala"), "Serializable")), Nil, Some(ValDef("_", Singleton(Ident("Foo3")), None)), List(DefDef("$lessinit$greater$default$1", Nil, Nil, Inferred(), Some(Literal(Constant(5))))))), Literal(Constant(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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), TypeSelect(Select(Ident("_root_"), "scala"), "Serializable")), 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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(Id("Foo7"))), ""), List(Literal(Constant(6))))), Literal(Constant(())))))))), Literal(Constant(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "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(())))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") diff --git a/tests/run-macros/tasty-extractors-3.check b/tests/run-macros/tasty-extractors-3.check index 05c9f0f2cb4b..57721c9234c2 100644 --- a/tests/run-macros/tasty-extractors-3.check +++ b/tests/run-macros/tasty-extractors-3.check @@ -1,44 +1,44 @@ -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Int") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Int") -Type.TermRef(NoPrefix(), "x") +TermRef(NoPrefix(), "x") -TypeBounds(Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Nothing"), Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Any")) +TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Nothing"), TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any")) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Nothing") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Nothing") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Any") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any") -Type.TypeRef(NoPrefix(), "T") +TypeRef(NoPrefix(), "T") -Type.TypeRef(NoPrefix(), "T") +TypeRef(NoPrefix(), "T") -TypeBounds(Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Int"), Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Int")) +TypeBounds(TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int"), TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int")) -Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Int") +TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int") -Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Int") +TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int") -Type.TypeRef(NoPrefix(), "T") +TypeRef(NoPrefix(), "T") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "lang")), "Object") +TypeRef(ThisType(TypeRef(NoPrefix(), "lang")), "Object") -TypeBounds(Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Nothing"), Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Any")) +TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Nothing"), TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any")) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Nothing") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Nothing") -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Any") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any") -Type.Refinement(Type.TypeRef(NoPrefix(), "Foo"), X, TypeBounds(Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Predef"), "String"), Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Predef"), "String"))) +Refinement(TypeRef(NoPrefix(), "Foo"), X, TypeBounds(TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "scala")), "Predef"), "String"), TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "scala")), "Predef"), "String"))) -Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Unit") +TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Type.TypeRef(NoPrefix(), "Foo") +TypeRef(NoPrefix(), "Foo") -Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Predef"), "String") +TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "scala")), "Predef"), "String") -Type.TypeRef(NoPrefix(), "$anon") +TypeRef(NoPrefix(), "$anon") -Type.Refinement(Type.TypeRef(NoPrefix(), "Foo"), X, TypeBounds(Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Predef"), "String"), Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Predef"), "String"))) +Refinement(TypeRef(NoPrefix(), "Foo"), X, TypeBounds(TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "scala")), "Predef"), "String"), TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "scala")), "Predef"), "String"))) diff --git a/tests/run-macros/tasty-extractors-types.check b/tests/run-macros/tasty-extractors-types.check index 9d5d03b2d628..b98c7b2536fe 100644 --- a/tests/run-macros/tasty-extractors-types.check +++ b/tests/run-macros/tasty-extractors-types.check @@ -1,12 +1,12 @@ Inferred() -Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Int") +TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int") Inferred() -Type.AppliedType(Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "immutable")), "List"), List(Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Predef"), "String"))) +AppliedType(TypeRef(ThisType(TypeRef(NoPrefix(), "immutable")), "List"), List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "scala")), "Predef"), "String"))) Inferred() -Type.AppliedType(Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "immutable")), "Map"), List(Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Predef"), "String"), Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "")), "scala"), "Int"))) +AppliedType(TypeRef(ThisType(TypeRef(NoPrefix(), "immutable")), "Map"), List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "scala")), "Predef"), "String"), TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int"))) Inferred() -Type.AppliedType(Type.TypeRef(Type.ThisType(Type.TypeRef(NoPrefix(), "immutable")), "Map"), List(Type.TypeRef(Type.TermRef(Type.ThisType(Type.TypeRef(NoPrefix(), "scala")), "Predef"), "String"), Type.TypeRef(NoPrefix(), "I"))) +AppliedType(TypeRef(ThisType(TypeRef(NoPrefix(), "immutable")), "Map"), List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "scala")), "Predef"), "String"), TypeRef(NoPrefix(), "I"))) diff --git a/tests/run-macros/tasty-indexed-map/quoted_1.scala b/tests/run-macros/tasty-indexed-map/quoted_1.scala index bae6fbf00040..c3907b54d137 100644 --- a/tests/run-macros/tasty-indexed-map/quoted_1.scala +++ b/tests/run-macros/tasty-indexed-map/quoted_1.scala @@ -29,11 +29,11 @@ object Index { import qctx.tasty.{_, given} def name(tp: TypeOrBounds): String = tp match { - case Type.ConstantType(Constant(str: String)) => str + case ConstantType(Constant(str: String)) => str } def names(tp: TypeOrBounds): List[String] = tp match { - case Type.AppliedType(_, x1 :: x2 :: Nil) => name(x1) :: names(x2) + case AppliedType(_, x1 :: x2 :: Nil) => name(x1) :: names(x2) case _ => Nil } diff --git a/tests/run-macros/tasty-macro-assert/quoted_1.scala b/tests/run-macros/tasty-macro-assert/quoted_1.scala index 7e2252f8ed4d..6c110c6c3eb4 100644 --- a/tests/run-macros/tasty-macro-assert/quoted_1.scala +++ b/tests/run-macros/tasty-macro-assert/quoted_1.scala @@ -18,7 +18,7 @@ object Asserts { val tree = cond.unseal def isOps(tpe: TypeOrBounds): Boolean = tpe match { - case Type.IsTermRef(tpe) => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts + case IsTermRef(tpe) => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts case _ => false } diff --git a/tests/run-macros/tasty-seal-method/quoted_1.scala b/tests/run-macros/tasty-seal-method/quoted_1.scala index 78cd9630aa3d..c8c000fdf21a 100644 --- a/tests/run-macros/tasty-seal-method/quoted_1.scala +++ b/tests/run-macros/tasty-seal-method/quoted_1.scala @@ -12,7 +12,7 @@ object Asserts { x.unseal.underlyingArgument match { case Apply(fn, args) => fn.tpe.widen match { - case Type.IsMethodType(_) => + case IsMethodType(_) => args.size match { case 0 => Expr.betaReduce(fn.seal.cast[() => Int])() case 1 => Expr.betaReduce(fn.seal.cast[Int => Int])('{0}) diff --git a/tests/run-macros/tasty-simplified/quoted_1.scala b/tests/run-macros/tasty-simplified/quoted_1.scala index c610dafc3944..e792437845d8 100644 --- a/tests/run-macros/tasty-simplified/quoted_1.scala +++ b/tests/run-macros/tasty-simplified/quoted_1.scala @@ -11,7 +11,7 @@ object Macros { def unpackTuple(tp: Type): List[Type] = { @tailrec def loop(tp: Type, acc: List[Type]): List[Type] = tp.dealias.simplified match { - case Type.AppliedType(_, List(IsType(hd), IsType(tl))) => + case AppliedType(_, List(IsType(hd), IsType(tl))) => loop(tl, hd.dealias.simplified :: acc) case other => acc } From 948b9dd8e3ce3695b7eb0fb43e444d3ff7507248 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 30 Oct 2019 13:30:02 +0100 Subject: [PATCH 2/2] Move extension methods near their modules --- .../scala/tasty/reflect/TypeOrBoundsOps.scala | 172 +++++++++--------- 1 file changed, 86 insertions(+), 86 deletions(-) diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala index 057dd6ff60eb..7543f2923c81 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala @@ -84,6 +84,10 @@ trait TypeOrBoundsOps extends Core { internal.matchConstantType(typeOrBounds).map(_.constant) } + given (self: ConstantType) { + def constant(given ctx: Context): Constant = internal.ConstantType_constant(self) + } + object IsTermRef { /** Matches any TermRef and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[TermRef] = @@ -97,6 +101,11 @@ trait TypeOrBoundsOps extends Core { internal.matchTermRef(typeOrBounds).map(x => (x.qualifier, x.name)) } + given (self: TermRef) { + def qualifier(given ctx: Context): TypeOrBounds /* Type | NoPrefix */ = internal.TermRef_qualifier(self) + def name(given ctx: Context): String = internal.TermRef_name(self) + } + object IsTypeRef { /** Matches any TypeRef and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[TypeRef] = @@ -108,6 +117,11 @@ trait TypeOrBoundsOps extends Core { internal.matchTypeRef(typeOrBounds).map(x => (x.qualifier, x.name)) } + given (self: TypeRef) { + def qualifier(given ctx: Context): TypeOrBounds /* Type | NoPrefix */ = internal.TypeRef_qualifier(self) + def name(given ctx: Context): String = internal.TypeRef_name(self) + } + object IsSuperType { /** Matches any SuperType and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[SuperType] = @@ -119,6 +133,11 @@ trait TypeOrBoundsOps extends Core { internal.matchSuperType(typeOrBounds).map(x => (x.thistpe, x.supertpe)) } + given (self: SuperType) { + def thistpe(given ctx: Context): Type = internal.SuperType_thistpe(self) + def supertpe(given ctx: Context): Type = internal.SuperType_supertpe(self) + } + object IsRefinement { /** Matches any Refinement and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[Refinement] = @@ -130,6 +149,12 @@ trait TypeOrBoundsOps extends Core { internal.matchRefinement(typeOrBounds).map(x => (x.parent, x.name, x.info)) } + given (self: Refinement) { + def parent(given ctx: Context): Type = internal.Refinement_parent(self) + def name(given ctx: Context): String = internal.Refinement_name(self) + def info(given ctx: Context): TypeOrBounds = internal.Refinement_info(self) + } + object IsAppliedType { /** Matches any AppliedType and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[AppliedType] = @@ -143,6 +168,11 @@ trait TypeOrBoundsOps extends Core { internal.matchAppliedType(typeOrBounds).map(x => (x.tycon, x.args)) } + given (self: AppliedType) { + def tycon(given ctx: Context): Type = internal.AppliedType_tycon(self) + def args(given ctx: Context): List[TypeOrBounds /* Type | TypeBounds */] = internal.AppliedType_args(self) + } + object IsAnnotatedType { /** Matches any AnnotatedType and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[AnnotatedType] = @@ -154,6 +184,11 @@ trait TypeOrBoundsOps extends Core { internal.matchAnnotatedType(typeOrBounds).map(x => (x.underlying, x.annot)) } + given (self: AnnotatedType) { + def underlying(given ctx: Context): Type = internal.AnnotatedType_underlying(self) + def annot(given ctx: Context): Term = internal.AnnotatedType_annot(self) + } + object IsAndType { /** Matches any AndType and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[AndType] = @@ -165,6 +200,11 @@ trait TypeOrBoundsOps extends Core { internal.matchAndType(typeOrBounds).map(x => (x.left, x.right)) } + given (self: AndType) { + def left(given ctx: Context): Type = internal.AndType_left(self) + def right(given ctx: Context): Type = internal.AndType_right(self) + } + object IsOrType { /** Matches any OrType and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[OrType] = @@ -176,6 +216,11 @@ trait TypeOrBoundsOps extends Core { internal.matchOrType(typeOrBounds).map(x => (x.left, x.right)) } + given (self: OrType) { + def left(given ctx: Context): Type = internal.OrType_left(self) + def right(given ctx: Context): Type = internal.OrType_right(self) + } + object IsMatchType { /** Matches any MatchType and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[MatchType] = @@ -187,6 +232,12 @@ trait TypeOrBoundsOps extends Core { internal.matchMatchType(typeOrBounds).map(x => (x.bound, x.scrutinee, x.cases)) } + given (self: MatchType) { + def bound(given ctx: Context): Type = internal.MatchType_bound(self) + def scrutinee(given ctx: Context): Type = internal.MatchType_scrutinee(self) + def cases(given ctx: Context): List[Type] = internal.MatchType_cases(self) + } + object IsByNameType { /** Matches any ByNameType and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[ByNameType] = @@ -198,6 +249,10 @@ trait TypeOrBoundsOps extends Core { internal.matchByNameType(typeOrBounds).map(_.underlying) } + given (self: ByNameType) { + def underlying(given ctx: Context): Type = internal.ByNameType_underlying(self) + } + object IsParamRef { /** Matches any ParamRef and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[ParamRef] = @@ -209,6 +264,11 @@ trait TypeOrBoundsOps extends Core { internal.matchParamRef(typeOrBounds).map(x => (x.binder, x.paramNum)) } + given (self: ParamRef) { + def binder(given ctx: Context): LambdaType[TypeOrBounds] = internal.ParamRef_binder(self) + def paramNum(given ctx: Context): Int = internal.ParamRef_paramNum(self) + } + object IsThisType { /** Matches any ThisType and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[ThisType] = @@ -220,6 +280,10 @@ trait TypeOrBoundsOps extends Core { internal.matchThisType(typeOrBounds).map(_.tref) } + given (self: ThisType) { + def tref(given ctx: Context): Type = internal.ThisType_tref(self) + } + object IsRecursiveThis { /** Matches any RecursiveThis and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[RecursiveThis] = @@ -231,6 +295,10 @@ trait TypeOrBoundsOps extends Core { internal.matchRecursiveThis(typeOrBounds).map(_.binder) } + given (self: RecursiveThis) { + def binder(given ctx: Context): RecursiveType = internal.RecursiveThis_binder(self) + } + object IsRecursiveType { /** Matches any RecursiveType and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[RecursiveType] = @@ -242,6 +310,10 @@ trait TypeOrBoundsOps extends Core { internal.matchRecursiveType(typeOrBounds).map(_.underlying) } + given (self: RecursiveType) { + def underlying(given ctx: Context): Type = internal.RecursiveType_underlying(self) + } + object IsMethodType { /** Matches any MethodType and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[MethodType] = @@ -253,6 +325,14 @@ trait TypeOrBoundsOps extends Core { internal.matchMethodType(typeOrBounds).map(x => (x.paramNames, x.paramTypes, x.resType)) } + given (self: MethodType) { + def isImplicit: Boolean = internal.MethodType_isImplicit(self) + def isErased: Boolean = internal.MethodType_isErased(self) + def paramNames(given ctx: Context): List[String] = internal.MethodType_paramNames(self) + def paramTypes(given ctx: Context): List[Type] = internal.MethodType_paramTypes(self) + def resType(given ctx: Context): Type = internal.MethodType_resType(self) + } + object IsPolyType { /** Matches any PolyType and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[PolyType] = @@ -264,6 +344,12 @@ trait TypeOrBoundsOps extends Core { internal.matchPolyType(typeOrBounds).map(x => (x.paramNames, x.paramBounds, x.resType)) } + given (self: PolyType) { + def paramNames(given ctx: Context): List[String] = internal.PolyType_paramNames(self) + def paramBounds(given ctx: Context): List[TypeBounds] = internal.PolyType_paramBounds(self) + def resType(given ctx: Context): Type = internal.PolyType_resType(self) + } + object IsTypeLambda { /** Matches any TypeLambda and returns it */ def unapply(tpe: TypeOrBounds)(given ctx: Context): Option[TypeLambda] = @@ -275,92 +361,6 @@ trait TypeOrBoundsOps extends Core { internal.matchTypeLambda(typeOrBounds).map(x => (x.paramNames, x.paramBounds, x.resType)) } - given (self: ConstantType) { - def constant(given ctx: Context): Constant = internal.ConstantType_constant(self) - } - - given (self: TermRef) { - def qualifier(given ctx: Context): TypeOrBounds /* Type | NoPrefix */ = internal.TermRef_qualifier(self) - def name(given ctx: Context): String = internal.TermRef_name(self) - } - - given (self: TypeRef) { - def qualifier(given ctx: Context): TypeOrBounds /* Type | NoPrefix */ = internal.TypeRef_qualifier(self) - def name(given ctx: Context): String = internal.TypeRef_name(self) - } - - given (self: SuperType) { - def thistpe(given ctx: Context): Type = internal.SuperType_thistpe(self) - def supertpe(given ctx: Context): Type = internal.SuperType_supertpe(self) - } - - given (self: Refinement) { - def parent(given ctx: Context): Type = internal.Refinement_parent(self) - def name(given ctx: Context): String = internal.Refinement_name(self) - def info(given ctx: Context): TypeOrBounds = internal.Refinement_info(self) - } - - given (self: AppliedType) { - def tycon(given ctx: Context): Type = internal.AppliedType_tycon(self) - def args(given ctx: Context): List[TypeOrBounds /* Type | TypeBounds */] = internal.AppliedType_args(self) - } - - given (self: AnnotatedType) { - def underlying(given ctx: Context): Type = internal.AnnotatedType_underlying(self) - def annot(given ctx: Context): Term = internal.AnnotatedType_annot(self) - } - - given (self: AndType) { - def left(given ctx: Context): Type = internal.AndType_left(self) - def right(given ctx: Context): Type = internal.AndType_right(self) - } - - given (self: OrType) { - def left(given ctx: Context): Type = internal.OrType_left(self) - def right(given ctx: Context): Type = internal.OrType_right(self) - } - - given (self: MatchType) { - def bound(given ctx: Context): Type = internal.MatchType_bound(self) - def scrutinee(given ctx: Context): Type = internal.MatchType_scrutinee(self) - def cases(given ctx: Context): List[Type] = internal.MatchType_cases(self) - } - - given (self: ByNameType) { - def underlying(given ctx: Context): Type = internal.ByNameType_underlying(self) - } - - given (self: ParamRef) { - def binder(given ctx: Context): LambdaType[TypeOrBounds] = internal.ParamRef_binder(self) - def paramNum(given ctx: Context): Int = internal.ParamRef_paramNum(self) - } - - given (self: ThisType) { - def tref(given ctx: Context): Type = internal.ThisType_tref(self) - } - - given (self: RecursiveThis) { - def binder(given ctx: Context): RecursiveType = internal.RecursiveThis_binder(self) - } - - given (self: RecursiveType) { - def underlying(given ctx: Context): Type = internal.RecursiveType_underlying(self) - } - - given (self: MethodType) { - def isImplicit: Boolean = internal.MethodType_isImplicit(self) - def isErased: Boolean = internal.MethodType_isErased(self) - def paramNames(given ctx: Context): List[String] = internal.MethodType_paramNames(self) - def paramTypes(given ctx: Context): List[Type] = internal.MethodType_paramTypes(self) - def resType(given ctx: Context): Type = internal.MethodType_resType(self) - } - - given (self: PolyType) { - def paramNames(given ctx: Context): List[String] = internal.PolyType_paramNames(self) - def paramBounds(given ctx: Context): List[TypeBounds] = internal.PolyType_paramBounds(self) - def resType(given ctx: Context): Type = internal.PolyType_resType(self) - } - given (self: TypeLambda) { def paramNames(given ctx: Context): List[String] = internal.TypeLambda_paramNames(self) def paramBounds(given ctx: Context): List[TypeBounds] = internal.TypeLambda_paramBounds(self)