From d5e134596d8908d894db57e8e4bf5c4099080753 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Sat, 9 Nov 2019 20:30:22 +0100 Subject: [PATCH 1/3] Fix #7204: Use evidence based type testing for unapplies * Deprecate `IsXYZ` extrators * Provide `IsInstanceOf[XYZ]` evidences * Refine the types of arguments of `unapply`s * Use `_: XYZ` instead of `IsXYZ(_)` in the dotty library --- .../ReflectionCompilerInterface.scala | 738 +++++++++++------- .../scala/tasty/reflect/TreeUtils.scala | 70 +- .../src/scala/internal/quoted/Matcher.scala | 14 +- library/src/scala/quoted/matching/Sym.scala | 2 +- .../src/scala/quoted/matching/package.scala | 4 +- .../tasty/reflect/CompilerInterface.scala | 166 ++-- .../scala/tasty/reflect/ImplicitsOps.scala | 45 +- .../tasty/reflect/ImportSelectorOps.scala | 24 +- .../scala/tasty/reflect/IsInstanceOf.scala | 39 + .../tasty/reflect/SourceCodePrinter.scala | 118 +-- library/src/scala/tasty/reflect/TreeOps.scala | 692 ++++++++-------- .../scala/tasty/reflect/TypeOrBoundsOps.scala | 279 ++++--- tests/neg-macros/i6976/Macro_1.scala | 2 +- .../fatal-warnings/tasty-parent-unapply.scala | 2 +- tests/pos/i7204.scala | 8 + tests/run-macros/i5715/Macro_1.scala | 3 +- tests/run-macros/i6171/Macro_1.scala | 6 +- tests/run-macros/reflect-dsl/assert_1.scala | 5 +- .../reflect-select-constructor/assert_1.scala | 5 +- .../assert_1.scala | 7 +- .../test_2.scala | 0 .../reflect-select-copy/assert_1.scala | 3 +- .../assert_1.scala | 5 +- .../reflect-select-value-class/assert_1.scala | 5 +- .../interpreter/TastyInterpreter.scala | 2 +- .../tasty-consumer/Test.scala | 4 +- 26 files changed, 1274 insertions(+), 974 deletions(-) create mode 100644 library/src/scala/tasty/reflect/IsInstanceOf.scala create mode 100644 tests/pos/i7204.scala rename tests/run-macros/{reflect-select-copy/reflect-select-copy => reflect-select-copy-2}/assert_1.scala (82%) rename tests/run-macros/{reflect-select-copy/reflect-select-copy => reflect-select-copy-2}/test_2.scala (100%) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala index d2bb51755f72..a44dd735f5a0 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala @@ -18,6 +18,8 @@ import dotty.tools.dotc.util.{SourceFile, SourcePosition, Spans} import scala.runtime.quoted.Unpickler import scala.tasty.reflect.CompilerInterface +import scala.tasty.reflect.IsInstanceOf + class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extends CompilerInterface { import tpd._ @@ -92,9 +94,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type PackageClause = tpd.PackageDef - def matchPackageClause(tree: Tree)(given Context): Option[PackageClause] = tree match { - case x: tpd.PackageDef => Some(x) - case _ => None + def isInstanceOfPackageClause(given ctx: Context): IsInstanceOf[PackageClause] = new { + def runtimeClass: Class[?] = classOf[PackageClause] + override def unapply(x: Any): Option[PackageClause] = x match + case x: tpd.PackageDef => Some(x) + case _ => None } def PackageClause_pid(self: PackageClause)(given Context): Ref = self.pid @@ -108,17 +112,22 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Statement = tpd.Tree - def matchStatement(tree: Tree)(given Context): Option[Statement] = tree match { - case _: PatternTree => None - case tree if tree.isTerm => matchTerm(tree) - case _ => matchDefinition(tree) + def isInstanceOfStatement(given ctx: Context): IsInstanceOf[Statement] = new { + def runtimeClass: Class[?] = classOf[Statement] + override def unapply(x: Any): Option[Statement] = x match + case _: PatternTree => None + case tree: Tree if tree.isTerm => isInstanceOfTerm.unapply(tree) + case tree: Tree => isInstanceOfDefinition.unapply(tree) + case _ => None } type Import = tpd.Import - def matchImport(tree: Tree)(given Context): Option[Import] = tree match { - case tree: tpd.Import => Some(tree) - case _ => None + def isInstanceOfImport(given ctx: Context): IsInstanceOf[Import] = new { + def runtimeClass: Class[?] = classOf[Import] + override def unapply(x: Any): Option[Import] = x match + case tree: tpd.Import => Some(tree) + case _ => None } def Import_implied(self: Import): Boolean = false // TODO: adapt to new import scheme @@ -133,10 +142,12 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Definition = tpd.Tree - def matchDefinition(tree: Tree)(given Context): Option[Definition] = tree match { - case tree: tpd.MemberDef => Some(tree) - case tree: PackageDefinition => Some(tree) - case _ => None + def isInstanceOfDefinition(given ctx: Context): IsInstanceOf[Definition] = new { + def runtimeClass: Class[?] = classOf[Definition] + override def unapply(x: Any): Option[Definition] = x match + case x: tpd.MemberDef => Some(x) + case x: PackageDefinition => Some(x) + case _ => None } def Definition_name(self: Definition)(given Context): String = self match { @@ -146,9 +157,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type PackageDef = PackageDefinition - def matchPackageDef(tree: Tree)(given Context): Option[PackageDef] = tree match { - case x: PackageDefinition => Some(x) - case _ => None + def isInstanceOfPackageDef(given ctx: Context): IsInstanceOf[PackageDef] = new { + def runtimeClass: Class[?] = classOf[PackageDef] + override def unapply(x: Any): Option[PackageDef] = x match + case x: PackageDefinition => Some(x) + case _ => None } def PackageDef_owner(self: PackageDef)(given Context): PackageDef = packageDefFromSym(self.symbol.owner) @@ -159,9 +172,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type ClassDef = tpd.TypeDef - def matchClassDef(tree: Tree)(given Context): Option[ClassDef] = tree match { - case x: tpd.TypeDef if x.isClassDef => Some(x) - case _ => None + def isInstanceOfClassDef(given ctx: Context): IsInstanceOf[ClassDef] = new { + def runtimeClass: Class[?] = classOf[ClassDef] + override def unapply(x: Any): Option[ClassDef] = x match + case x: tpd.TypeDef if x.isClassDef => Some(x) + case _ => None } def ClassDef_constructor(self: ClassDef)(given Context): DefDef = ClassDef_rhs(self).constr @@ -178,9 +193,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type TypeDef = tpd.TypeDef - def matchTypeDef(tree: Tree)(given Context): Option[TypeDef] = tree match { - case x: tpd.TypeDef if !x.symbol.isClass => Some(x) - case _ => None + def isInstanceOfTypeDef(given ctx: Context): IsInstanceOf[TypeDef] = new { + def runtimeClass: Class[?] = classOf[TypeDef] + override def unapply(x: Any): Option[TypeDef] = x match + case x: tpd.TypeDef if !x.symbol.isClass => Some(x) + case _ => None } def TypeDef_rhs(self: TypeDef)(given Context): TypeTree | TypeBoundsTree = self.rhs @@ -191,9 +208,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type DefDef = tpd.DefDef - def matchDefDef(tree: Tree)(given Context): Option[DefDef] = tree match { - case x: tpd.DefDef => Some(x) - case _ => None + def isInstanceOfDefDef(given ctx: Context): IsInstanceOf[DefDef] = new { + def runtimeClass: Class[?] = classOf[DefDef] + override def unapply(x: Any): Option[DefDef] = x match + case x: tpd.DefDef => Some(x) + case _ => None } def DefDef_typeParams(self: DefDef)(given Context): List[TypeDef] = self.tparams @@ -209,9 +228,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type ValDef = tpd.ValDef - def matchValDef(tree: Tree)(given Context): Option[ValDef] = tree match { - case x: tpd.ValDef => Some(x) - case _ => None + def isInstanceOfValDef(given ctx: Context): IsInstanceOf[ValDef] = new { + def runtimeClass: Class[?] = classOf[ValDef] + override def unapply(x: Any): Option[ValDef] = x match + case x: tpd.ValDef => Some(x) + case _ => None } def ValDef_tpt(self: ValDef)(given Context): TypeTree = self.tpt @@ -225,12 +246,14 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Term = tpd.Tree - def matchTerm(tree: Tree)(given Context): Option[Term] = tree match { - case _ if matchTree_Unapply(tree).isDefined => None - case _: PatternTree => None - case x: tpd.SeqLiteral => Some(tree) - case _ if tree.isTerm => Some(tree) - case _ => None + def isInstanceOfTerm(given ctx: Context): IsInstanceOf[Term] = new { + def runtimeClass: Class[?] = classOf[Term] + override def unapply(x: Any): Option[Term] = x match + case _ if isInstanceOfUnapply.unapply(x).isDefined => None + case _: PatternTree => None + case x: tpd.SeqLiteral => Some(x) + case x: Tree if x.isTerm => Some(x) + case _ => None } def Term_tpe(self: Term)(given Context): Type = self.tpe @@ -251,9 +274,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Ref = tpd.RefTree - def matchRef(tree: Tree)(given Context): Option[Ref] = tree match { - case x: tpd.RefTree if x.isTerm => Some(x) - case _ => None + def isInstanceOfRef(given ctx: Context): IsInstanceOf[Ref] = new { + def runtimeClass: Class[?] = classOf[Ref] + override def unapply(x: Any): Option[Ref] = x match + case x: tpd.RefTree if x.isTerm => Some(x) + case _ => None } def Ref_apply(sym: Symbol)(given Context): Ref = @@ -261,9 +286,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Ident = tpd.Ident - def matchIdent(x: Term)(given Context): Option[Ident] = x match { - case x: tpd.Ident if x.isTerm => Some(x) - case _ => None + def isInstanceOfIdent(given ctx: Context): IsInstanceOf[Ident] = new { + def runtimeClass: Class[?] = classOf[Ident] + override def unapply(x: Any): Option[Ident] = x match + case x: tpd.Ident if x.isTerm => Some(x) + case _ => None } def Ident_name(self: Ident)(given Context): String = self.name.show @@ -276,9 +303,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Select = tpd.Select - def matchSelect(x: Term)(given Context): Option[Select] = x match { - case x: tpd.Select if x.isTerm => Some(x) - case _ => None + def isInstanceOfSelect(given ctx: Context): IsInstanceOf[Select] = new { + def runtimeClass: Class[?] = classOf[Select] + override def unapply(x: Any): Option[Select] = x match + case x: tpd.Select if x.isTerm => Some(x) + case _ => None } def Select_qualifier(self: Select)(given Context): Term = self.qualifier @@ -305,9 +334,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Literal = tpd.Literal - def matchLiteral(x: Term)(given Context): Option[Literal] = x match { - case x: tpd.Literal => Some(x) - case _ => None + def isInstanceOfLiteral(given ctx: Context): IsInstanceOf[Literal] = new { + def runtimeClass: Class[?] = classOf[Literal] + override def unapply(x: Any): Option[Literal] = x match + case x: tpd.Literal => Some(x) + case _ => None } def Literal_constant(self: Literal)(given Context): Constant = self.const @@ -320,9 +351,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type This = tpd.This - def matchThis(x: Term)(given Context): Option[This] = x match { - case x: tpd.This => Some(x) - case _ => None + def isInstanceOfThis(given ctx: Context): IsInstanceOf[This] = new { + def runtimeClass: Class[?] = classOf[This] + override def unapply(x: Any): Option[This] = x match + case x: tpd.This => Some(x) + case _ => None } def This_id(self: This)(given Context): Option[Id] = optional(self.qual) @@ -335,9 +368,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type New = tpd.New - def matchNew(x: Term)(given Context): Option[New] = x match { - case x: tpd.New => Some(x) - case _ => None + def isInstanceOfNew(given ctx: Context): IsInstanceOf[New] = new { + def runtimeClass: Class[?] = classOf[New] + override def unapply(x: Any): Option[New] = x match + case x: tpd.New => Some(x) + case _ => None } def New_tpt(self: New)(given Context): TypeTree = self.tpt @@ -349,9 +384,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type NamedArg = tpd.NamedArg - def matchNamedArg(x: Term)(given Context): Option[NamedArg] = x match { - case x: tpd.NamedArg if x.name.isInstanceOf[core.Names.TermName] => Some(x) // TODO: Now, the name should alwas be a term name - case _ => None + def isInstanceOfNamedArg(given ctx: Context): IsInstanceOf[NamedArg] = new { + def runtimeClass: Class[?] = classOf[NamedArg] + override def unapply(x: Any): Option[NamedArg] = x match + case x: tpd.NamedArg if x.name.isInstanceOf[core.Names.TermName] => Some(x) // TODO: Now, the name should alwas be a term name + case _ => None } def NamedArg_name(self: NamedArg)(given Context): String = self.name.toString @@ -365,9 +402,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Apply = tpd.Apply - def matchApply(x: Term)(given Context): Option[Apply] = x match { - case x: tpd.Apply => Some(x) - case _ => None + def isInstanceOfApply(given ctx: Context): IsInstanceOf[Apply] = new { + def runtimeClass: Class[?] = classOf[Apply] + override def unapply(x: Any): Option[Apply] = x match + case x: tpd.Apply => Some(x) + case _ => None } def Apply_fun(self: Apply)(given Context): Term = self.fun @@ -382,9 +421,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type TypeApply = tpd.TypeApply - def matchTypeApply(x: Term)(given Context): Option[TypeApply] = x match { - case x: tpd.TypeApply => Some(x) - case _ => None + def isInstanceOfTypeApply(given ctx: Context): IsInstanceOf[TypeApply] = new { + def runtimeClass: Class[?] = classOf[TypeApply] + override def unapply(x: Any): Option[TypeApply] = x match + case x: tpd.TypeApply => Some(x) + case _ => None } def TypeApply_fun(self: TypeApply)(given Context): Term = self.fun @@ -398,9 +439,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Super = tpd.Super - def matchSuper(x: Term)(given Context): Option[Super] = x match { - case x: tpd.Super => Some(x) - case _ => None + def isInstanceOfSuper(given ctx: Context): IsInstanceOf[Super] = new { + def runtimeClass: Class[?] = classOf[Super] + override def unapply(x: Any): Option[Super] = x match + case x: tpd.Super => Some(x) + case _ => None } def Super_qualifier(self: Super)(given Context): Term = self.qual @@ -414,9 +457,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Typed = tpd.Typed - def matchTyped(x: Term)(given Context): Option[Typed] = x match { - case x: tpd.Typed => Some(x) - case _ => None + def isInstanceOfTyped(given ctx: Context): IsInstanceOf[Typed] = new { + def runtimeClass: Class[?] = classOf[Typed] + override def unapply(x: Any): Option[Typed] = x match + case x: tpd.Typed => Some(x) + case _ => None } def Typed_expr(self: Typed)(given Context): Term = self.expr @@ -430,9 +475,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Assign = tpd.Assign - def matchAssign(x: Term)(given Context): Option[Assign] = x match { - case x: tpd.Assign => Some(x) - case _ => None + def isInstanceOfAssign(given ctx: Context): IsInstanceOf[Assign] = new { + def runtimeClass: Class[?] = classOf[Assign] + override def unapply(x: Any): Option[Assign] = x match + case x: tpd.Assign => Some(x) + case _ => None } def Assign_lhs(self: Assign)(given Context): Term = self.lhs @@ -446,9 +493,15 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Block = tpd.Block - def matchBlock(x: Term)(given Context): Option[Block] = normalizedLoops(x) match { - case x: tpd.Block => Some(x) - case _ => None + def isInstanceOfBlock(given ctx: Context): IsInstanceOf[Block] = new { + def runtimeClass: Class[?] = classOf[Block] + override def unapply(x: Any): Option[Block] = + x match + case x: tpd.Tree => + normalizedLoops(x) match + case y: tpd.Block => Some(y) + case _ => None + case _ => None } /** Normalizes non Blocks. @@ -492,9 +545,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Inlined = tpd.Inlined - def matchInlined(x: Term)(given Context): Option[Inlined] = x match { - case x: tpd.Inlined => Some(x) - case _ => None + def isInstanceOfInlined(given ctx: Context): IsInstanceOf[Inlined] = new { + def runtimeClass: Class[?] = classOf[Inlined] + override def unapply(x: Any): Option[Inlined] = x match + case x: tpd.Inlined => Some(x) + case _ => None } def Inlined_call(self: Inlined)(given Context): Option[Term | TypeTree] = optional(self.call) @@ -509,9 +564,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Closure = tpd.Closure - def matchClosure(x: Term)(given Context): Option[Closure] = x match { - case x: tpd.Closure => Some(x) - case _ => None + def isInstanceOfClosure(given ctx: Context): IsInstanceOf[Closure] = new { + def runtimeClass: Class[?] = classOf[Closure] + override def unapply(x: Any): Option[Closure] = x match + case x: tpd.Closure => Some(x) + case _ => None } def Closure_meth(self: Closure)(given Context): Term = self.meth @@ -525,9 +582,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type If = tpd.If - def matchIf(x: Term)(given Context): Option[If] = x match { - case x: tpd.If => Some(x) - case _ => None + def isInstanceOfIf(given ctx: Context): IsInstanceOf[If] = new { + def runtimeClass: Class[?] = classOf[If] + override def unapply(x: Any): Option[If] = x match + case x: tpd.If => Some(x) + case _ => None } def If_cond(self: If)(given Context): Term = self.cond @@ -542,9 +601,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Match = tpd.Match - def matchMatch(x: Term)(given Context): Option[Match] = x match { - case x: tpd.Match if !x.selector.isEmpty => Some(x) - case _ => None + def isInstanceOfMatch(given ctx: Context): IsInstanceOf[Match] = new { + def runtimeClass: Class[?] = classOf[Match] + override def unapply(x: Any): Option[Match] = x match + case x: tpd.Match if !x.selector.isEmpty => Some(x) + case _ => None } def Match_scrutinee(self: Match)(given Context): Term = self.selector @@ -558,9 +619,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type ImpliedMatch = tpd.Match - def matchImplicitMatch(x: Term)(given Context): Option[Match] = x match { - case x: tpd.Match if x.selector.isEmpty => Some(x) - case _ => None + def isInstanceOfImpliedMatch(given ctx: Context): IsInstanceOf[ImpliedMatch] = new { + def runtimeClass: Class[?] = classOf[ImpliedMatch] + override def unapply(x: Any): Option[ImpliedMatch] = x match + case x: tpd.Match if x.selector.isEmpty => Some(x) + case _ => None } def ImplicitMatch_cases(self: Match)(given Context): List[CaseDef] = self.cases @@ -573,9 +636,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Try = tpd.Try - def matchTry(x: Term)(given Context): Option[Try] = x match { - case x: tpd.Try => Some(x) - case _ => None + def isInstanceOfTry(given ctx: Context): IsInstanceOf[Try] = new { + def runtimeClass: Class[?] = classOf[Try] + override def unapply(x: Any): Option[Try] = x match + case x: tpd.Try => Some(x) + case _ => None } def Try_body(self: Try)(given Context): Term = self.expr @@ -590,9 +655,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Return = tpd.Return - def matchReturn(x: Term)(given Context): Option[Return] = x match { - case x: tpd.Return => Some(x) - case _ => None + def isInstanceOfReturn(given ctx: Context): IsInstanceOf[Return] = new { + def runtimeClass: Class[?] = classOf[Return] + override def unapply(x: Any): Option[Return] = x match + case x: tpd.Return => Some(x) + case _ => None } def Return_expr(self: Return)(given Context): Term = self.expr @@ -605,9 +672,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Repeated = tpd.SeqLiteral - def matchRepeated(x: Term)(given Context): Option[Repeated] = x match { - case x: tpd.SeqLiteral => Some(x) - case _ => None + def isInstanceOfRepeated(given ctx: Context): IsInstanceOf[Repeated] = new { + def runtimeClass: Class[?] = classOf[Repeated] + override def unapply(x: Any): Option[Repeated] = x match + case x: tpd.SeqLiteral => Some(x) + case _ => None } def Repeated_elems(self: Repeated)(given Context): List[Term] = self.elems @@ -621,12 +690,13 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type SelectOuter = tpd.Select - def matchSelectOuter(x: Term)(given Context): Option[SelectOuter] = x match { + def isInstanceOfSelectOuter(given ctx: Context): IsInstanceOf[SelectOuter] = new { + def runtimeClass: Class[?] = classOf[SelectOuter] + override def unapply(x: Any): Option[SelectOuter] = x match case x: tpd.Select => - x.name match { + x.name match case NameKinds.OuterSelectName(_, _) => Some(x) case _ => None - } case _ => None } @@ -644,9 +714,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type While = tpd.WhileDo - def matchWhile(x: Term)(given Context): Option[While] = x match { - case x: tpd.WhileDo => Some(x) - case _ => None + def isInstanceOfWhile(given ctx: Context): IsInstanceOf[While] = new { + def runtimeClass: Class[?] = classOf[While] + override def unapply(x: Any): Option[While] = x match + case x: tpd.WhileDo => Some(x) + case _ => None } def While_cond(self: While)(given Context): Term = self.cond @@ -660,27 +732,34 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type TypeTree = tpd.Tree - def matchTypeTree(x: TypeTree | TypeBoundsTree)(given Context): Option[TypeTree] = x match { - case x: tpd.TypeBoundsTree => None - case _ => if (x.isType) Some(x) else None + def isInstanceOfTypeTree(given ctx: Context): IsInstanceOf[TypeTree] = new { + def runtimeClass: Class[?] = classOf[TypeTree] + override def unapply(x: Any): Option[TypeTree] = x match + case x: tpd.TypeBoundsTree => None + case x: tpd.Tree if x.isType => Some(x) + case _ => None } def TypeTree_tpe(self: TypeTree)(given Context): Type = self.tpe.stripTypeVar type Inferred = tpd.TypeTree - def matchInferred(tpt: TypeTree | TypeBoundsTree)(given Context): Option[Inferred] = tpt match { - case tpt: tpd.TypeTree if !tpt.tpe.isInstanceOf[Types.TypeBounds] => Some(tpt) - case _ => None + def isInstanceOfInferred(given ctx: Context): IsInstanceOf[Inferred] = new { + def runtimeClass: Class[?] = classOf[Inferred] + override def unapply(x: Any): Option[Inferred] = x match + case tpt: tpd.TypeTree if !tpt.tpe.isInstanceOf[Types.TypeBounds] => Some(tpt) + case _ => None } def Inferred_apply(tpe: Type)(given Context): Inferred = withDefaultPos(tpd.TypeTree(tpe)) type TypeIdent = tpd.Ident - def matchTypeIdent(tpt: TypeTree | TypeBoundsTree)(given Context): Option[TypeIdent] = tpt match { - case tpt: tpd.Ident if tpt.isType => Some(tpt) - case _ => None + def isInstanceOfTypeIdent(given ctx: Context): IsInstanceOf[TypeIdent] = new { + def runtimeClass: Class[?] = classOf[TypeIdent] + override def unapply(x: Any): Option[TypeIdent] = x match + case tpt: tpd.Ident if tpt.isType => Some(tpt) + case _ => None } def TypeIdent_name(self: TypeIdent)(given Context): String = self.name.toString @@ -690,9 +769,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type TypeSelect = tpd.Select - def matchTypeSelect(tpt: TypeTree | TypeBoundsTree)(given Context): Option[TypeSelect] = tpt match { - case tpt: tpd.Select if tpt.isType && tpt.qualifier.isTerm => Some(tpt) - case _ => None + def isInstanceOfTypeSelect(given ctx: Context): IsInstanceOf[TypeSelect] = new { + def runtimeClass: Class[?] = classOf[TypeSelect] + override def unapply(x: Any): Option[TypeSelect] = x match + case tpt: tpd.Select if tpt.isType && tpt.qualifier.isTerm => Some(tpt) + case _ => None } def TypeSelect_qualifier(self: TypeSelect)(given Context): Term = self.qualifier @@ -707,9 +788,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Projection = tpd.Select - def matchProjection(tpt: TypeTree | TypeBoundsTree)(given Context): Option[Projection] = tpt match { - case tpt: tpd.Select if tpt.isType && tpt.qualifier.isType => Some(tpt) - case _ => None + def isInstanceOfProjection(given ctx: Context): IsInstanceOf[Projection] = new { + def runtimeClass: Class[?] = classOf[Projection] + override def unapply(x: Any): Option[Projection] = x match + case tpt: tpd.Select if tpt.isType && tpt.qualifier.isType => Some(tpt) + case _ => None } def Projection_qualifier(self: Projection)(given Context): TypeTree = self.qualifier @@ -720,9 +803,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Singleton = tpd.SingletonTypeTree - def matchSingleton(tpt: TypeTree | TypeBoundsTree)(given Context): Option[Singleton] = tpt match { - case tpt: tpd.SingletonTypeTree => Some(tpt) - case _ => None + def isInstanceOfSingleton(given ctx: Context): IsInstanceOf[Singleton] = new { + def runtimeClass: Class[?] = classOf[Singleton] + override def unapply(x: Any): Option[Singleton] = x match + case tpt: tpd.SingletonTypeTree => Some(tpt) + case _ => None } def Singleton_ref(self: Singleton)(given Context): Term = self.ref @@ -735,9 +820,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Refined = tpd.RefinedTypeTree - def matchRefined(tpt: TypeTree | TypeBoundsTree)(given Context): Option[Refined] = tpt match { - case tpt: tpd.RefinedTypeTree => Some(tpt) - case _ => None + def isInstanceOfRefined(given ctx: Context): IsInstanceOf[Refined] = new { + def runtimeClass: Class[?] = classOf[Refined] + override def unapply(x: Any): Option[Refined] = x match + case tpt: tpd.RefinedTypeTree => Some(tpt) + case _ => None } def Refined_tpt(self: Refined)(given Context): TypeTree = self.tpt @@ -748,9 +835,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Applied = tpd.AppliedTypeTree - def matchApplied(tpt: TypeTree | TypeBoundsTree)(given Context): Option[Applied] = tpt match { - case tpt: tpd.AppliedTypeTree => Some(tpt) - case _ => None + def isInstanceOfApplied(given ctx: Context): IsInstanceOf[Applied] = new { + def runtimeClass: Class[?] = classOf[Applied] + override def unapply(x: Any): Option[Applied] = x match + case tpt: tpd.AppliedTypeTree => Some(tpt) + case _ => None } def Applied_tpt(self: Applied)(given Context): TypeTree = self.tpt @@ -764,9 +853,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Annotated = tpd.Annotated - def matchAnnotated(tpt: TypeTree | TypeBoundsTree)(given Context): Option[Annotated] = tpt match { - case tpt: tpd.Annotated => Some(tpt) - case _ => None + def isInstanceOfAnnotated(given ctx: Context): IsInstanceOf[Annotated] = new { + def runtimeClass: Class[?] = classOf[Annotated] + override def unapply(x: Any): Option[Annotated] = x match + case tpt: tpd.Annotated => Some(tpt) + case _ => None } def Annotated_arg(self: Annotated)(given Context): TypeTree = self.arg @@ -780,9 +871,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type MatchTypeTree = tpd.MatchTypeTree - def matchMatchTypeTree(tpt: TypeTree | TypeBoundsTree)(given Context): Option[MatchTypeTree] = tpt match { - case tpt: tpd.MatchTypeTree => Some(tpt) - case _ => None + def isInstanceOfMatchTypeTree(given ctx: Context): IsInstanceOf[MatchTypeTree] = new { + def runtimeClass: Class[?] = classOf[MatchTypeTree] + override def unapply(x: Any): Option[MatchTypeTree] = x match + case tpt: tpd.MatchTypeTree => Some(tpt) + case _ => None } def MatchTypeTree_bound(self: MatchTypeTree)(given Context): Option[TypeTree] = if (self.bound == tpd.EmptyTree) None else Some(self.bound) @@ -797,9 +890,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type ByName = tpd.ByNameTypeTree - def matchByName(tpt: TypeTree | TypeBoundsTree)(given Context): Option[ByName] = tpt match { - case tpt: tpd.ByNameTypeTree => Some(tpt) - case _ => None + def isInstanceOfByName(given ctx: Context): IsInstanceOf[ByName] = new { + def runtimeClass: Class[?] = classOf[ByName] + override def unapply(x: Any): Option[ByName] = x match + case tpt: tpd.ByNameTypeTree => Some(tpt) + case _ => None } def ByName_result(self: ByName)(given Context): TypeTree = self.result @@ -812,9 +907,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type LambdaTypeTree = tpd.LambdaTypeTree - def matchLambdaTypeTree(tpt: TypeTree | TypeBoundsTree)(given Context): Option[LambdaTypeTree] = tpt match { - case tpt: tpd.LambdaTypeTree => Some(tpt) - case _ => None + def isInstanceOfLambdaTypeTree(given ctx: Context): IsInstanceOf[LambdaTypeTree] = new { + def runtimeClass: Class[?] = classOf[LambdaTypeTree] + override def unapply(x: Any): Option[LambdaTypeTree] = x match + case tpt: tpd.LambdaTypeTree => Some(tpt) + case _ => None } def Lambdatparams(self: LambdaTypeTree)(given Context): List[TypeDef] = self.tparams @@ -828,9 +925,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type TypeBind = tpd.Bind - def matchTypeBind(tpt: TypeTree | TypeBoundsTree)(given Context): Option[TypeBind] = tpt match { - case tpt: tpd.Bind if tpt.name.isTypeName => Some(tpt) - case _ => None + def isInstanceOfTypeBind(given ctx: Context): IsInstanceOf[TypeBind] = new { + def runtimeClass: Class[?] = classOf[TypeBind] + override def unapply(x: Any): Option[TypeBind] = x match + case tpt: tpd.Bind if tpt.name.isTypeName => Some(tpt) + case _ => None } def TypeBind_name(self: TypeBind)(given Context): String = self.name.toString @@ -841,9 +940,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type TypeBlock = tpd.Block - def matchTypeBlock(tpt: TypeTree | TypeBoundsTree)(given Context): Option[TypeBlock] = tpt match { - case tpt: tpd.Block => Some(tpt) - case _ => None + def isInstanceOfTypeBlock(given ctx: Context): IsInstanceOf[TypeBlock] = new { + def runtimeClass: Class[?] = classOf[TypeBlock] + override def unapply(x: Any): Option[TypeBlock] = x match + case tpt: tpd.Block => Some(tpt) + case _ => None } def TypeBlock_aliases(self: TypeBlock)(given Context): List[TypeDef] = self.stats.map { case alias: TypeDef => alias } @@ -857,16 +958,18 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type TypeBoundsTree = tpd.TypeBoundsTree - def matchTypeBoundsTree(x: TypeTree | TypeBoundsTree)(given Context): Option[TypeBoundsTree] = x match { - case x: tpd.TypeBoundsTree => Some(x) - case x @ Trees.TypeTree() => - // TODO only enums generate this kind of type bounds. Is this possible without enums? If not generate tpd.TypeBoundsTree for enums instead - x.tpe match { - case tpe: Types.TypeBounds => - Some(tpd.TypeBoundsTree(tpd.TypeTree(tpe.lo).withSpan(x.span), tpd.TypeTree(tpe.hi).withSpan(x.span))) - case _ => None - } - case _ => None + def isInstanceOfTypeBoundsTree(given ctx: Context): IsInstanceOf[TypeBoundsTree] = new { + def runtimeClass: Class[?] = classOf[TypeBoundsTree] + override def unapply(x: Any): Option[TypeBoundsTree] = x match + case x: tpd.TypeBoundsTree => Some(x) + case x @ tpd.TypeTree() => + // TODO only enums generate this kind of type bounds. Is this possible without enums? If not generate tpd.TypeBoundsTree for enums instead + (x.tpe: Any) match { + case tpe: Types.TypeBounds => + Some(tpd.TypeBoundsTree(tpd.TypeTree(tpe.lo).withSpan(x.span), tpd.TypeTree(tpe.hi).withSpan(x.span))) + case _ => None + } + case _ => None } def TypeBoundsTree_tpe(self: TypeBoundsTree)(given Context): TypeBounds = self.tpe.asInstanceOf[Types.TypeBounds] @@ -875,18 +978,22 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type WildcardTypeTree = tpd.Ident - def matchWildcardTypeTree(x: TypeTree | TypeBoundsTree)(given Context): Option[WildcardTypeTree] = x match { - case x @ Trees.Ident(nme.WILDCARD) => Some(x) - case _ => None + def isInstanceOfWildcardTypeTree(given ctx: Context): IsInstanceOf[WildcardTypeTree] = new { + def runtimeClass: Class[?] = classOf[WildcardTypeTree] + override def unapply(x: Any): Option[WildcardTypeTree] = x match + case x: tpd.Ident if x.name == nme.WILDCARD => Some(x) + case _ => None } def WildcardTypeTree_tpe(self: WildcardTypeTree)(given Context): TypeOrBounds = self.tpe.stripTypeVar type CaseDef = tpd.CaseDef - def matchCaseDef(tree: Tree)(given Context): Option[CaseDef] = tree match { - case tree: tpd.CaseDef if tree.body.isTerm => Some(tree) - case _ => None + def isInstanceOfCaseDef(given ctx: Context): IsInstanceOf[CaseDef] = new { + def runtimeClass: Class[?] = classOf[CaseDef] + override def unapply(x: Any): Option[CaseDef] = x match + case tree: tpd.CaseDef if tree.body.isTerm => Some(tree) + case _ => None } def CaseDef_pattern(self: CaseDef)(given Context): Tree = self.pat @@ -901,9 +1008,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type TypeCaseDef = tpd.CaseDef - def matchTypeCaseDef(tree: Tree)(given Context): Option[TypeCaseDef] = tree match { - case tree: tpd.CaseDef if tree.body.isType => Some(tree) - case _ => None + def isInstanceOfTypeCaseDef(given ctx: Context): IsInstanceOf[TypeCaseDef] = new { + def runtimeClass: Class[?] = classOf[TypeCaseDef] + override def unapply(x: Any): Option[TypeCaseDef] = x match + case tree: tpd.CaseDef if tree.body.isType => Some(tree) + case _ => None } def TypeCaseDef_pattern(self: TypeCaseDef)(given Context): TypeTree = self.pat @@ -917,9 +1026,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Bind = tpd.Bind - def matchTree_Bind(x: Tree)(given Context): Option[Bind] = x match { - case x: tpd.Bind if x.name.isTermName => Some(x) - case _ => None + def isInstanceOfBind(given ctx: Context): IsInstanceOf[Bind] = new { + def runtimeClass: Class[?] = classOf[Bind] + override def unapply(x: Any): Option[Bind] = x match + case x: tpd.Bind if x.name.isTermName => Some(x) + case _ => None } def Tree_Bind_name(self: Bind)(given Context): String = self.name.toString @@ -931,10 +1042,12 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Unapply = tpd.UnApply - def matchTree_Unapply(pattern: Tree)(given Context): Option[Unapply] = pattern match { - case pattern @ Trees.UnApply(_, _, _) => Some(pattern) - case Trees.Typed(pattern @ Trees.UnApply(_, _, _), _) => Some(pattern) - case _ => None + def isInstanceOfUnapply(given ctx: Context): IsInstanceOf[Unapply] = new { + def runtimeClass: Class[?] = classOf[Unapply] + override def unapply(x: Any): Option[Unapply] = x match + case pattern: tpd.UnApply => Some(pattern) + case Trees.Typed(pattern: tpd.UnApply, _) => Some(pattern) + case _ => None } def Tree_Unapply_fun(self: Unapply)(given Context): Term = self.fun @@ -951,9 +1064,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Alternatives = tpd.Alternative - def matchTree_Alternatives(pattern: Tree)(given Context): Option[Alternatives] = pattern match { - case pattern: tpd.Alternative => Some(pattern) - case _ => None + def isInstanceOfAlternatives(given ctx: Context): IsInstanceOf[Alternatives] = new { + def runtimeClass: Class[?] = classOf[Alternatives] + override def unapply(x: Any): Option[Alternatives] = x match + case x: tpd.Alternative => Some(x) + case _ => None } def Tree_Alternatives_patterns(self: Alternatives)(given Context): List[Tree] = self.trees @@ -972,14 +1087,19 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type NoPrefix = Types.NoPrefix.type - def matchNoPrefix(x: TypeOrBounds)(given Context): Option[NoPrefix] = - if (x == Types.NoPrefix) Some(Types.NoPrefix) else None + def isInstanceOfNoPrefix(given ctx: Context): IsInstanceOf[NoPrefix] = new { + def runtimeClass: Class[?] = classOf[Types.NoPrefix.type] + override def unapply(x: Any): Option[NoPrefix] = + if (x == Types.NoPrefix) Some(Types.NoPrefix) else None + } type TypeBounds = Types.TypeBounds - def matchTypeBounds(x: TypeOrBounds)(given Context): Option[TypeBounds] = x match { - case x: Types.TypeBounds => Some(x) - case _ => None + def isInstanceOfTypeBounds(given ctx: Context): IsInstanceOf[TypeBounds] = new { + def runtimeClass: Class[?] = classOf[TypeBounds] + override def unapply(x: Any): Option[TypeBounds] = x match + case x: Types.TypeBounds => Some(x) + case _ => None } def TypeBounds_low(self: TypeBounds)(given Context): Type = self.lo @@ -987,10 +1107,12 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Type = Types.Type - def matchType(x: TypeOrBounds)(given Context): Option[Type] = x match { - case x: TypeBounds => None - case x if x == Types.NoPrefix => None - case _ => Some(x) + def isInstanceOfType(given ctx: Context): IsInstanceOf[Type] = new { + def runtimeClass: Class[?] = classOf[Type] + override def unapply(x: Any): Option[Type] = x match + case x: TypeBounds => None + case x: Types.Type if x != Types.NoPrefix => Some(x) + case _ => None } def Type_apply(clazz: Class[?])(given ctx: Context): Type = @@ -1065,18 +1187,22 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type ConstantType = Types.ConstantType - def matchConstantType(tpe: TypeOrBounds)(given Context): Option[ConstantType] = tpe match { - case tpe: Types.ConstantType => Some(tpe) - case _ => None + def isInstanceOfConstantType(given ctx: Context): IsInstanceOf[ConstantType] = new { + def runtimeClass: Class[?] = classOf[ConstantType] + override def unapply(x: Any): Option[ConstantType] = x match + case tpe: Types.ConstantType => Some(tpe) + case _ => None } def ConstantType_constant(self: ConstantType)(given Context): Constant = self.value type TermRef = Types.NamedType - def matchTermRef(tpe: TypeOrBounds)(given Context): Option[TermRef] = tpe match { - case tp: Types.TermRef => Some(tp) - case _ => None + def isInstanceOfTermRef(given ctx: Context): IsInstanceOf[TermRef] = new { + def runtimeClass: Class[?] = classOf[TermRef] + override def unapply(x: Any): Option[TermRef] = x match + case tp: Types.TermRef => Some(tp) + case _ => None } def TermRef_apply(qual: TypeOrBounds, name: String)(given Context): TermRef = @@ -1088,9 +1214,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type TypeRef = Types.NamedType - def matchTypeRef(tpe: TypeOrBounds)(given Context): Option[TypeRef] = tpe match { - case tp: Types.TypeRef => Some(tp) - case _ => None + def isInstanceOfTypeRef(given ctx: Context): IsInstanceOf[TypeRef] = new { + def runtimeClass: Class[?] = classOf[TypeRef] + override def unapply(x: Any): Option[TypeRef] = x match + case tp: Types.TypeRef => Some(tp) + case _ => None } def TypeRef_qualifier(self: TypeRef)(given Context): TypeOrBounds = self.prefix @@ -1099,13 +1227,15 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type NamedTermRef = Types.NamedType - def matchNamedTermRef(tpe: TypeOrBounds)(given Context): Option[NamedTermRef] = tpe match { - case tpe: Types.NamedType => - tpe.designator match { - case name: Names.TermName => Some(tpe) - case _ => None - } - case _ => None + def isInstanceOfNamedTermRef(given ctx: Context): IsInstanceOf[NamedTermRef] = new { + def runtimeClass: Class[?] = classOf[NamedTermRef] + override def unapply(x: Any): Option[NamedTermRef] = x match + case tpe: Types.NamedType => + tpe.designator match { + case name: Names.TermName => Some(tpe) + case _ => None + } + case _ => None } def NamedTermRef_name(self: NamedTermRef)(given Context): String = self.name.toString @@ -1113,9 +1243,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type SuperType = Types.SuperType - def matchSuperType(tpe: TypeOrBounds)(given Context): Option[SuperType] = tpe match { - case tpe: Types.SuperType => Some(tpe) - case _ => None + def isInstanceOfSuperType(given ctx: Context): IsInstanceOf[SuperType] = new { + def runtimeClass: Class[?] = classOf[SuperType] + override def unapply(x: Any): Option[SuperType] = x match + case tpe: Types.SuperType => Some(tpe) + case _ => None } def SuperType_thistpe(self: SuperType)(given Context): Type = self.thistpe @@ -1123,9 +1255,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type Refinement = Types.RefinedType - def matchRefinement(tpe: TypeOrBounds)(given Context): Option[Refinement] = tpe match { - case tpe: Types.RefinedType => Some(tpe) - case _ => None + def isInstanceOfRefinement(given ctx: Context): IsInstanceOf[Refinement] = new { + def runtimeClass: Class[?] = classOf[Refinement] + override def unapply(x: Any): Option[Refinement] = x match + case tpe: Types.RefinedType => Some(tpe) + case _ => None } def Refinement_parent(self: Refinement)(given Context): Type = self.parent @@ -1134,9 +1268,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type AppliedType = Types.AppliedType - def matchAppliedType(tpe: TypeOrBounds)(given Context): Option[AppliedType] = tpe match { - case tpe: Types.AppliedType => Some(tpe) - case _ => None + def isInstanceOfAppliedType(given ctx: Context): IsInstanceOf[AppliedType] = new { + def runtimeClass: Class[?] = classOf[AppliedType] + override def unapply(x: Any): Option[AppliedType] = x match + case tpe: Types.AppliedType => Some(tpe) + case _ => None } def AppliedType_tycon(self: AppliedType)(given Context): Type = self.tycon @@ -1146,9 +1282,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type AnnotatedType = Types.AnnotatedType - def matchAnnotatedType(tpe: TypeOrBounds)(given Context): Option[AnnotatedType] = tpe match { - case tpe: Types.AnnotatedType => Some(tpe) - case _ => None + def isInstanceOfAnnotatedType(given ctx: Context): IsInstanceOf[AnnotatedType] = new { + def runtimeClass: Class[?] = classOf[AnnotatedType] + override def unapply(x: Any): Option[AnnotatedType] = x match + case tpe: Types.AnnotatedType => Some(tpe) + case _ => None } def AnnotatedType_underlying(self: AnnotatedType)(given Context): Type = self.underlying.stripTypeVar @@ -1156,9 +1294,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type AndType = Types.AndType - def matchAndType(tpe: TypeOrBounds)(given Context): Option[AndType] = tpe match { - case tpe: Types.AndType => Some(tpe) - case _ => None + def isInstanceOfAndType(given ctx: Context): IsInstanceOf[AndType] = new { + def runtimeClass: Class[?] = classOf[AndType] + override def unapply(x: Any): Option[AndType] = x match + case tpe: Types.AndType => Some(tpe) + case _ => None } def AndType_left(self: AndType)(given Context): Type = self.tp1.stripTypeVar @@ -1166,9 +1306,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type OrType = Types.OrType - def matchOrType(tpe: TypeOrBounds)(given Context): Option[OrType] = tpe match { - case tpe: Types.OrType => Some(tpe) - case _ => None + def isInstanceOfOrType(given ctx: Context): IsInstanceOf[OrType] = new { + def runtimeClass: Class[?] = classOf[OrType] + override def unapply(x: Any): Option[OrType] = x match + case tpe: Types.OrType => Some(tpe) + case _ => None } def OrType_left(self: OrType)(given Context): Type = self.tp1.stripTypeVar @@ -1176,9 +1318,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type MatchType = Types.MatchType - def matchMatchType(tpe: TypeOrBounds)(given Context): Option[MatchType] = tpe match { - case tpe: Types.MatchType => Some(tpe) - case _ => None + def isInstanceOfMatchType(given ctx: Context): IsInstanceOf[MatchType] = new { + def runtimeClass: Class[?] = classOf[MatchType] + override def unapply(x: Any): Option[MatchType] = x match + case tpe: Types.MatchType => Some(tpe) + case _ => None } def MatchType_bound(self: MatchType)(given Context): Type = self.bound @@ -1187,19 +1331,23 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type ByNameType = Types.ExprType - def matchByNameType(tpe: TypeOrBounds)(given Context): Option[ByNameType] = tpe match { - case tpe: Types.ExprType => Some(tpe) - case _ => None + def isInstanceOfByNameType(given ctx: Context): IsInstanceOf[ByNameType] = new { + def runtimeClass: Class[?] = classOf[ByNameType] + override def unapply(x: Any): Option[ByNameType] = x match + case tpe: Types.ExprType => Some(tpe) + case _ => None } def ByNameType_underlying(self: ByNameType)(given Context): Type = self.resType.stripTypeVar type ParamRef = Types.ParamRef - def matchParamRef(tpe: TypeOrBounds)(given Context): Option[ParamRef] = tpe match { - case tpe: Types.TypeParamRef => Some(tpe) - case tpe: Types.TermParamRef => Some(tpe) - case _ => None + def isInstanceOfParamRef(given ctx: Context): IsInstanceOf[ParamRef] = new { + def runtimeClass: Class[?] = classOf[ParamRef] + override def unapply(x: Any): Option[ParamRef] = x match + case tpe: Types.TypeParamRef => Some(tpe) + case tpe: Types.TermParamRef => Some(tpe) + case _ => None } def ParamRef_binder(self: ParamRef)(given Context): LambdaType[TypeOrBounds] = @@ -1208,27 +1356,33 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type ThisType = Types.ThisType - def matchThisType(tpe: TypeOrBounds)(given Context): Option[ThisType] = tpe match { - case tpe: Types.ThisType => Some(tpe) - case _ => None + def isInstanceOfThisType(given ctx: Context): IsInstanceOf[ThisType] = new { + def runtimeClass: Class[?] = classOf[ThisType] + override def unapply(x: Any): Option[ThisType] = x match + case tpe: Types.ThisType => Some(tpe) + case _ => None } def ThisType_tref(self: ThisType)(given Context): Type = self.tref type RecursiveThis = Types.RecThis - def matchRecursiveThis(tpe: TypeOrBounds)(given Context): Option[RecursiveThis] = tpe match { - case tpe: Types.RecThis => Some(tpe) - case _ => None + def isInstanceOfRecursiveThis(given ctx: Context): IsInstanceOf[RecursiveThis] = new { + def runtimeClass: Class[?] = classOf[RecursiveThis] + override def unapply(x: Any): Option[RecursiveThis] = x match + case tpe: Types.RecThis => Some(tpe) + case _ => None } def RecursiveThis_binder(self: RecursiveThis)(given Context): RecursiveType = self.binder type RecursiveType = Types.RecType - def matchRecursiveType(tpe: TypeOrBounds)(given Context): Option[RecursiveType] = tpe match { - case tpe: Types.RecType => Some(tpe) - case _ => None + def isInstanceOfRecursiveType(given ctx: Context): IsInstanceOf[RecursiveType] = new { + def runtimeClass: Class[?] = classOf[RecursiveType] + override def unapply(x: Any): Option[RecursiveType] = x match + case tpe: Types.RecType => Some(tpe) + case _ => None } def RecursiveType_underlying(self: RecursiveType)(given Context): Type = self.underlying.stripTypeVar @@ -1237,9 +1391,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type MethodType = Types.MethodType - def matchMethodType(tpe: TypeOrBounds)(given Context): Option[MethodType] = tpe match { - case tpe: Types.MethodType => Some(tpe) - case _ => None + def isInstanceOfMethodType(given ctx: Context): IsInstanceOf[MethodType] = new { + def runtimeClass: Class[?] = classOf[MethodType] + override def unapply(x: Any): Option[MethodType] = x match + case tpe: Types.MethodType => Some(tpe) + case _ => None } def MethodType_isErased(self: MethodType): Boolean = self.isErasedMethod @@ -1250,9 +1406,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type PolyType = Types.PolyType - def matchPolyType(tpe: TypeOrBounds)(given Context): Option[PolyType] = tpe match { - case tpe: Types.PolyType => Some(tpe) - case _ => None + def isInstanceOfPolyType(given ctx: Context): IsInstanceOf[PolyType] = new { + def runtimeClass: Class[?] = classOf[PolyType] + override def unapply(x: Any): Option[PolyType] = x match + case tpe: Types.PolyType => Some(tpe) + case _ => None } def PolyType_paramNames(self: PolyType)(given Context): List[String] = self.paramNames.map(_.toString) @@ -1261,9 +1419,11 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type TypeLambda = Types.TypeLambda - def matchTypeLambda(tpe: TypeOrBounds)(given Context): Option[TypeLambda] = tpe match { - case tpe: Types.TypeLambda => Some(tpe) - case _ => None + def isInstanceOfTypeLambda(given ctx: Context): IsInstanceOf[TypeLambda] = new { + def runtimeClass: Class[?] = classOf[TypeLambda] + override def unapply(x: Any): Option[TypeLambda] = x match + case tpe: Types.TypeLambda => Some(tpe) + case _ => None } def TypeLambda_paramNames(self: TypeLambda)(given Context): List[String] = self.paramNames.map(_.toString) @@ -1278,15 +1438,23 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type SimpleSelector = untpd.ImportSelector - def matchSimpleSelector(self: ImportSelector)(given Context): Option[SimpleSelector] = - if self.renamed.isEmpty then Some(self) else None // TODO: handle import bounds + def isInstanceOfSimpleSelector(given ctx: Context): IsInstanceOf[SimpleSelector] = new { + def runtimeClass: Class[?] = classOf[SimpleSelector] + override def unapply(x: Any): Option[SimpleSelector] = x match + case x: untpd.ImportSelector if x.renamed.isEmpty => Some(x) + case _ => None // TODO: handle import bounds + } def SimpleSelector_selection(self: SimpleSelector)(given Context): Id = self.imported type RenameSelector = untpd.ImportSelector - def matchRenameSelector(self: ImportSelector)(given Context): Option[RenameSelector] = - if self.renamed.isEmpty then None else Some(self) + def isInstanceOfRenameSelector(given ctx: Context): IsInstanceOf[RenameSelector] = new { + def runtimeClass: Class[?] = classOf[RenameSelector] + override def unapply(x: Any): Option[RenameSelector] = x match + case x: untpd.ImportSelector if !x.renamed.isEmpty => Some(x) + case _ => None + } def RenameSelector_from(self: RenameSelector)(given Context): Id = self.imported @@ -1295,10 +1463,17 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend type OmitSelector = untpd.ImportSelector - def matchOmitSelector(self: ImportSelector)(given Context): Option[OmitSelector] = - self.renamed match - case Trees.Ident(nme.WILDCARD) => Some(self) + def isInstanceOfOmitSelector(given ctx: Context): IsInstanceOf[OmitSelector] = new { + def runtimeClass: Class[?] = classOf[OmitSelector] + override def unapply(x: Any): Option[OmitSelector] = x match { + case self: untpd.ImportSelector => + self.renamed match + case Trees.Ident(nme.WILDCARD) => Some(self) + case _ => None case _ => None + } + + } def SimpleSelector_omitted(self: OmitSelector)(given Context): Id = self.imported @@ -1716,36 +1891,61 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend ctx.typer.inferImplicitArg(tpe, rootPosition.span) type ImplicitSearchSuccess = Tree - def matchImplicitSearchSuccess(isr: ImplicitSearchResult)(given Context): Option[ImplicitSearchSuccess] = isr.tpe match { - case _: SearchFailureType => None - case _ => Some(isr) + def isInstanceOfImplicitSearchSuccess(given ctx: Context): IsInstanceOf[ImplicitSearchSuccess] = new { + def runtimeClass: Class[?] = classOf[ImplicitSearchSuccess] + override def unapply(x: Any): Option[ImplicitSearchSuccess] = x match + case x: Tree => + x.tpe match + case _: SearchFailureType => None + case _ => Some(x) + case _ => None } def ImplicitSearchSuccess_tree(self: ImplicitSearchSuccess)(given Context): Term = self type ImplicitSearchFailure = Tree - def matchImplicitSearchFailure(isr: ImplicitSearchResult)(given Context): Option[ImplicitSearchFailure] = isr.tpe match { - case _: SearchFailureType => Some(isr) - case _ => None + def isInstanceOfImplicitSearchFailure(given ctx: Context): IsInstanceOf[ImplicitSearchFailure] = new { + def runtimeClass: Class[?] = classOf[ImplicitSearchFailure] + override def unapply(x: Any): Option[ImplicitSearchFailure] = x match + case x: Tree => + x.tpe match + case _: SearchFailureType => Some(x) + case _ => None + case _ => None } def ImplicitSearchFailure_explanation(self: ImplicitSearchFailure)(given Context): String = self.tpe.asInstanceOf[SearchFailureType].explanation type DivergingImplicit = Tree - def matchDivergingImplicit(isr: ImplicitSearchResult)(given Context): Option[DivergingImplicit] = isr.tpe match { - case _: Implicits.DivergingImplicit => Some(isr) - case _ => None + def isInstanceOfDivergingImplicit(given ctx: Context): IsInstanceOf[DivergingImplicit] = new { + def runtimeClass: Class[?] = classOf[DivergingImplicit] + override def unapply(x: Any): Option[DivergingImplicit] = x match + case x: Tree => + x.tpe match + case _: Implicits.DivergingImplicit => Some(x) + case _ => None + case _ => None } type NoMatchingImplicits = Tree - def matchNoMatchingImplicits(isr: ImplicitSearchResult)(given Context): Option[NoMatchingImplicits] = isr.tpe match { - case _: Implicits.NoMatchingImplicits => Some(isr) - case _ => None + def isInstanceOfNoMatchingImplicits(given ctx: Context): IsInstanceOf[NoMatchingImplicits] = new { + def runtimeClass: Class[?] = classOf[NoMatchingImplicits] + override def unapply(x: Any): Option[NoMatchingImplicits] = x match + case x: Tree => + x.tpe match + case _: Implicits.NoMatchingImplicits => Some(x) + case _ => None + case _ => None } type AmbiguousImplicits = Tree - def matchAmbiguousImplicits(isr: ImplicitSearchResult)(given Context): Option[AmbiguousImplicits] = isr.tpe match { - case _: Implicits.AmbiguousImplicits => Some(isr) - case _ => None + def isInstanceOfAmbiguousImplicits(given ctx: Context): IsInstanceOf[AmbiguousImplicits] = new { + def runtimeClass: Class[?] = classOf[AmbiguousImplicits] + override def unapply(x: Any): Option[AmbiguousImplicits] = x match + case x: Tree => + x.tpe match + case _: Implicits.AmbiguousImplicits => Some(x) + case _ => None + case _ => None } def betaReduce(fn: Term, args: List[Term])(given ctx: Context): Term = { @@ -1769,7 +1969,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend newOwners = ctx.owner :: Nil, treeMap = tree => paramToVals.get(tree.symbol).map(_.withSpan(tree.span)).getOrElse(tree) ).transform(ddef.rhs) - case Block(stats, expr) => + case tpd.Block(stats, expr) => seq(stats, rec(expr)).withSpan(fn.span) case _ => fn.select(nme.apply).appliedToArgs(argRefs).withSpan(fn.span) diff --git a/library/src-bootstrapped/scala/tasty/reflect/TreeUtils.scala b/library/src-bootstrapped/scala/tasty/reflect/TreeUtils.scala index 9d22cae6f978..6c3d2342f673 100644 --- a/library/src-bootstrapped/scala/tasty/reflect/TreeUtils.scala +++ b/library/src-bootstrapped/scala/tasty/reflect/TreeUtils.scala @@ -57,21 +57,21 @@ trait TreeUtils foldTrees(foldTree(x, elemtpt), elems) case Inlined(call, bindings, expansion) => foldTree(foldTrees(x, bindings), expansion) - case IsDefinition(vdef @ ValDef(_, tpt, rhs)) => + case vdef @ ValDef(_, tpt, rhs) => implicit val ctx = localCtx(vdef) foldTrees(foldTree(x, tpt), rhs) - case IsDefinition(ddef @ DefDef(_, tparams, vparamss, tpt, rhs)) => + case ddef @ DefDef(_, tparams, vparamss, tpt, rhs) => implicit val ctx = localCtx(ddef) foldTrees(foldTree(vparamss.foldLeft(foldTrees(x, tparams))(foldTrees), tpt), rhs) - case IsDefinition(tdef @ TypeDef(_, rhs)) => + case tdef @ TypeDef(_, rhs) => implicit val ctx = localCtx(tdef) foldTree(x, rhs) - case IsDefinition(cdef @ ClassDef(_, constr, parents, derived, self, body)) => + case cdef @ ClassDef(_, constr, parents, derived, self, body) => implicit val ctx = localCtx(cdef) foldTrees(foldTrees(foldTrees(foldTrees(foldTree(x, constr), parents), derived), self), body) case Import(expr, _) => foldTree(x, expr) - case IsPackageClause(clause @ PackageClause(pid, stats)) => + case clause @ PackageClause(pid, stats) => foldTrees(foldTree(x, pid), stats)(given clause.symbol.localContext) case Inferred() => x case TypeIdent(_) => x @@ -112,24 +112,24 @@ trait TreeUtils def transformTree(tree: Tree)(given ctx: Context): Tree = { tree match { - case IsPackageClause(tree) => + case tree: PackageClause => PackageClause.copy(tree)(transformTerm(tree.pid).asInstanceOf[Ref], transformTrees(tree.stats)(given tree.symbol.localContext)) - case IsImport(tree) => + case tree: Import => Import.copy(tree)(transformTerm(tree.expr), tree.selectors) - case IsStatement(tree) => + case tree: Statement => transformStatement(tree) - case IsTypeTree(tree) => transformTypeTree(tree) - case IsTypeBoundsTree(tree) => tree // TODO traverse tree - case IsWildcardTypeTree(tree) => tree // TODO traverse tree - case IsCaseDef(tree) => + case tree: TypeTree => transformTypeTree(tree) + case tree: TypeBoundsTree => tree // TODO traverse tree + case tree: WildcardTypeTree => tree // TODO traverse tree + case tree: CaseDef => transformCaseDef(tree) - case IsTypeCaseDef(tree) => + case tree: TypeCaseDef => transformTypeCaseDef(tree) - case IsBind(pattern) => + case pattern: Bind => Bind.copy(pattern)(pattern.name, pattern.pattern) - case IsUnapply(pattern) => + case pattern: Unapply => Unapply.copy(pattern)(transformTerm(pattern.fun), transformSubTrees(pattern.implicits), transformTrees(pattern.patterns)) - case IsAlternatives(pattern) => + case pattern: Alternatives => Alternatives.copy(pattern)(transformTrees(pattern.patterns)) } } @@ -137,22 +137,22 @@ trait TreeUtils def transformStatement(tree: Statement)(given ctx: Context): Statement = { def localCtx(definition: Definition): Context = definition.symbol.localContext tree match { - case IsTerm(tree) => + case tree: Term => transformTerm(tree) - case IsValDef(tree) => + case tree: ValDef => implicit val ctx = localCtx(tree) val tpt1 = transformTypeTree(tree.tpt) val rhs1 = tree.rhs.map(x => transformTerm(x)) ValDef.copy(tree)(tree.name, tpt1, rhs1) - case IsDefDef(tree) => + case tree: DefDef => implicit val ctx = localCtx(tree) DefDef.copy(tree)(tree.name, transformSubTrees(tree.typeParams), tree.paramss mapConserve (transformSubTrees(_)), transformTypeTree(tree.returnTpt), tree.rhs.map(x => transformTerm(x))) - case IsTypeDef(tree) => + case tree: TypeDef => implicit val ctx = localCtx(tree) TypeDef.copy(tree)(tree.name, transformTree(tree.rhs)) - case IsClassDef(tree) => + case tree: ClassDef => ClassDef.copy(tree)(tree.name, tree.constructor, tree.parents, tree.derived, tree.self, tree.body) - case IsImport(tree) => + case tree: Import => Import.copy(tree)(transformTerm(tree.expr), tree.selectors) } } @@ -177,7 +177,7 @@ trait TreeUtils New.copy(tree)(transformTypeTree(tpt)) case Typed(expr, tpt) => Typed.copy(tree)(transformTerm(expr), transformTypeTree(tpt)) - case IsNamedArg(tree) => + case tree: NamedArg => NamedArg.copy(tree)(tree.name, transformTerm(tree.value)) case Assign(lhs, rhs) => Assign.copy(tree)(transformTerm(lhs), transformTerm(rhs)) @@ -204,28 +204,28 @@ trait TreeUtils def transformTypeTree(tree: TypeTree)(given ctx: Context): TypeTree = tree match { case Inferred() => tree - case IsTypeIdent(tree) => tree - case IsTypeSelect(tree) => + case tree: TypeIdent => tree + case tree: TypeSelect => TypeSelect.copy(tree)(tree.qualifier, tree.name) - case IsProjection(tree) => + case tree: Projection => Projection.copy(tree)(tree.qualifier, tree.name) - case IsAnnotated(tree) => + case tree: Annotated => Annotated.copy(tree)(tree.arg, tree.annotation) - case IsSingleton(tree) => + case tree: Singleton => Singleton.copy(tree)(transformTerm(tree.ref)) - case IsRefined(tree) => + case tree: Refined => Refined.copy(tree)(transformTypeTree(tree.tpt), transformTrees(tree.refinements).asInstanceOf[List[Definition]]) - case IsApplied(tree) => + case tree: Applied => Applied.copy(tree)(transformTypeTree(tree.tpt), transformTrees(tree.args)) - case IsMatchTypeTree(tree) => + case tree: MatchTypeTree => MatchTypeTree.copy(tree)(tree.bound.map(b => transformTypeTree(b)), transformTypeTree(tree.selector), transformTypeCaseDefs(tree.cases)) - case IsByName(tree) => + case tree: ByName => ByName.copy(tree)(transformTypeTree(tree.result)) - case IsLambdaTypeTree(tree) => + case tree: LambdaTypeTree => LambdaTypeTree.copy(tree)(transformSubTrees(tree.tparams), transformTree(tree.body))(given tree.symbol.localContext) - case IsTypeBind(tree) => + case tree: TypeBind => TypeBind.copy(tree)(tree.name, tree.body) - case IsTypeBlock(tree) => + case tree: TypeBlock => TypeBlock.copy(tree)(tree.aliases, tree.tpt) } diff --git a/library/src/scala/internal/quoted/Matcher.scala b/library/src/scala/internal/quoted/Matcher.scala index af99fbdc027f..2acfeea99207 100644 --- a/library/src/scala/internal/quoted/Matcher.scala +++ b/library/src/scala/internal/quoted/Matcher.scala @@ -131,14 +131,14 @@ private[quoted] object Matcher { (scrutinee, pattern) match { // Match a scala.internal.Quoted.patternHole typed as a repeated argument and return the scrutinee tree - case (IsTerm(scrutinee @ Typed(s, tpt1)), Typed(TypeApply(patternHole, tpt :: Nil), tpt2)) + case (scrutinee @ Typed(s, tpt1), Typed(TypeApply(patternHole, tpt :: Nil), tpt2)) if patternHole.symbol == internal.Definitions_InternalQuoted_patternHole && s.tpe <:< tpt.tpe && tpt2.tpe.derivesFrom(defn.RepeatedParamClass) => matched(scrutinee.seal) // Match a scala.internal.Quoted.patternHole and return the scrutinee tree - case (IsTerm(scrutinee), TypeApply(patternHole, tpt :: Nil)) + case (scrutinee: Term, TypeApply(patternHole, tpt :: Nil)) if patternHole.symbol == internal.Definitions_InternalQuoted_patternHole && scrutinee.tpe <:< tpt.tpe => matched(scrutinee.seal) @@ -162,7 +162,7 @@ private[quoted] object Matcher { case (Select(qual1, _), Select(qual2, _)) if scrutinee.symbol == pattern.symbol => qual1 =?= qual2 - case (IsRef(_), IsRef(_)) if scrutinee.symbol == pattern.symbol => + case (_: Ref, _: Ref) if scrutinee.symbol == pattern.symbol => matched case (Apply(fn1, args1), Apply(fn2, args2)) if fn1.symbol == fn2.symbol => @@ -209,7 +209,7 @@ private[quoted] object Matcher { case (Repeated(elems1, _), Repeated(elems2, _)) if elems1.size == elems2.size => elems1 =?= elems2 - case (IsTypeTree(scrutinee), IsTypeTree(pattern)) if scrutinee.tpe <:< pattern.tpe => + case (scrutinee: TypeTree, pattern: TypeTree) if scrutinee.tpe <:< pattern.tpe => matched case (Applied(tycon1, args1), Applied(tycon2, args2)) => @@ -306,7 +306,7 @@ private[quoted] object Matcher { * `None` if it did not match or `Some(tup: Tuple)` if it matched where `tup` contains the contents of the holes. */ private def patternsMatches(scrutinee: Tree, pattern: Tree)(given Context, Env): (Env, Matching) = (scrutinee, pattern) match { - case (IsTerm(v1), Unapply(TypeApply(Select(patternHole @ Ident("patternHole"), "unapply"), List(tpt)), Nil, Nil)) + case (v1: Term, Unapply(TypeApply(Select(patternHole @ Ident("patternHole"), "unapply"), List(tpt)), Nil, Nil)) if patternHole.symbol.owner.fullName == "scala.runtime.quoted.Matcher$" => (summon[Env], matched(v1.seal)) @@ -327,7 +327,7 @@ private[quoted] object Matcher { case (Typed(Ident("_"), tpt1), Typed(Ident("_"), tpt2)) => (summon[Env], tpt1 =?= tpt2) - case (IsTerm(v1), IsTerm(v2)) => + case (v1: Term, v2: Term) => (summon[Env], v1 =?= v2) case _ => @@ -360,7 +360,7 @@ private[quoted] object Matcher { } private def isTypeBinding(tree: Tree): Boolean = tree match { - case IsTypeDef(tree) => hasBindAnnotation(tree.symbol) + case tree: TypeDef => hasBindAnnotation(tree.symbol) case _ => false } } diff --git a/library/src/scala/quoted/matching/Sym.scala b/library/src/scala/quoted/matching/Sym.scala index afcae7718296..069b43409c0d 100644 --- a/library/src/scala/quoted/matching/Sym.scala +++ b/library/src/scala/quoted/matching/Sym.scala @@ -22,7 +22,7 @@ object Sym { def unapply[T](expr: Expr[T])(given qctx: QuoteContext): Option[Sym[T]] = { import qctx.tasty.{_, given} expr.unseal match { - case IsIdent(ref) => + case ref: Ident => val sym = ref.symbol Some(new Sym[T](sym.name, sym)) case _ => None diff --git a/library/src/scala/quoted/matching/package.scala b/library/src/scala/quoted/matching/package.scala index fad5fa0ed2d1..334b18615e0f 100644 --- a/library/src/scala/quoted/matching/package.scala +++ b/library/src/scala/quoted/matching/package.scala @@ -13,8 +13,8 @@ package object matching { def searchImplicitExpr[T](given tpe: Type[T], qctx: QuoteContext): Option[Expr[T]] = { import qctx.tasty.{_, given} searchImplicit(tpe.unseal.tpe) match { - case IsImplicitSearchSuccess(iss) => Some(iss.tree.seal.asInstanceOf[Expr[T]]) - case IsImplicitSearchFailure(isf) => None + case iss: ImplicitSearchSuccess => Some(iss.tree.seal.asInstanceOf[Expr[T]]) + case isf: ImplicitSearchFailure => None } } diff --git a/library/src/scala/tasty/reflect/CompilerInterface.scala b/library/src/scala/tasty/reflect/CompilerInterface.scala index 39f21f5b66b9..b1abe512d948 100644 --- a/library/src/scala/tasty/reflect/CompilerInterface.scala +++ b/library/src/scala/tasty/reflect/CompilerInterface.scala @@ -186,7 +186,7 @@ trait CompilerInterface { /** Tree representing a pacakage clause in the source code */ type PackageClause <: Tree - def matchPackageClause(tree: Tree)(given ctx: Context): Option[PackageClause] + def isInstanceOfPackageClause(given ctx: Context): IsInstanceOf[PackageClause] def PackageClause_pid(self: PackageClause)(given ctx: Context): Ref def PackageClause_stats(self: PackageClause)(given ctx: Context): List[Tree] @@ -198,12 +198,12 @@ trait CompilerInterface { /** Tree representing a statement in the source code */ type Statement <: Tree - def matchStatement(tree: Tree)(given ctx: Context): Option[Statement] + def isInstanceOfStatement(given ctx: Context): IsInstanceOf[Statement] /** Tree representing an import in the source code */ type Import <: Statement - def matchImport(tree: Tree)(given ctx: Context): Option[Import] + def isInstanceOfImport(given ctx: Context): IsInstanceOf[Import] def Import_implied(self: Import): Boolean def Import_expr(self: Import)(given ctx: Context): Term @@ -216,14 +216,14 @@ trait CompilerInterface { /** Tree representing a definition in the source code. It can be `PackageDef`, `ClassDef`, `TypeDef`, `DefDef` or `ValDef` */ type Definition <: Statement - def matchDefinition(tree: Tree)(given ctx: Context): Option[Definition] + def isInstanceOfDefinition(given ctx: Context): IsInstanceOf[Definition] def Definition_name(self: Definition)(given ctx: Context): String /** Tree representing a package definition. This includes definitions in all source files */ type PackageDef <: Definition - def matchPackageDef(tree: Tree)(given ctx: Context): Option[PackageDef] + def isInstanceOfPackageDef(given ctx: Context): IsInstanceOf[PackageDef] def PackageDef_owner(self: PackageDef)(given ctx: Context): PackageDef def PackageDef_members(self: PackageDef)(given ctx: Context): List[Statement] @@ -231,7 +231,7 @@ trait CompilerInterface { /** Tree representing a class definition. This includes annonymus class definitions and the class of a module object */ type ClassDef <: Definition - def matchClassDef(tree: Tree)(given ctx: Context): Option[ClassDef] + def isInstanceOfClassDef(given ctx: Context): IsInstanceOf[ClassDef] def ClassDef_constructor(self: ClassDef)(given ctx: Context): DefDef def ClassDef_parents(self: ClassDef)(given ctx: Context): List[Tree/* Term | TypeTree */] @@ -244,7 +244,7 @@ trait CompilerInterface { /** Tree representing a type (paramter or member) definition in the source code */ type TypeDef <: Definition - def matchTypeDef(tree: Tree)(given ctx: Context): Option[TypeDef] + def isInstanceOfTypeDef(given ctx: Context): IsInstanceOf[TypeDef] def TypeDef_rhs(self: TypeDef)(given ctx: Context): Tree /*TypeTree | TypeBoundsTree*/ @@ -254,7 +254,7 @@ trait CompilerInterface { /** Tree representing a method definition in the source code */ type DefDef <: Definition - def matchDefDef(tree: Tree)(given ctx: Context): Option[DefDef] + def isInstanceOfDefDef(given ctx: Context): IsInstanceOf[DefDef] def DefDef_typeParams(self: DefDef)(given ctx: Context): List[TypeDef] def DefDef_paramss(self: DefDef)(given ctx: Context): List[List[ValDef]] @@ -267,7 +267,7 @@ trait CompilerInterface { /** Tree representing a value definition in the source code This inclues `val`, `lazy val`, `var`, `object` and parameter definitions. */ type ValDef <: Definition - def matchValDef(tree: Tree)(given ctx: Context): Option[ValDef] + def isInstanceOfValDef(given ctx: Context): IsInstanceOf[ValDef] def ValDef_tpt(self: ValDef)(given ctx: Context): TypeTree def ValDef_rhs(self: ValDef)(given ctx: Context): Option[Term] @@ -278,7 +278,7 @@ trait CompilerInterface { /** Tree representing an expression in the source code */ type Term <: Statement - def matchTerm(tree: Tree)(given ctx: Context): Option[Term] + def isInstanceOfTerm(given ctx: Context): IsInstanceOf[Term] def Term_tpe(self: Term)(given ctx: Context): Type def Term_underlyingArgument(self: Term)(given ctx: Context): Term @@ -288,14 +288,14 @@ trait CompilerInterface { /** Tree representing a reference to definition */ type Ref <: Term - def matchRef(tree: Tree)(given ctx: Context): Option[Ref] + def isInstanceOfRef(given ctx: Context): IsInstanceOf[Ref] def Ref_apply(sym: Symbol)(given ctx: Context): Ref /** Tree representing a reference to definition with a given name */ type Ident <: Ref - def matchIdent(tree: Tree)(given ctx: Context): Option[Ident] + def isInstanceOfIdent(given ctx: Context): IsInstanceOf[Ident] def Ident_name(self: Ident)(given ctx: Context): String @@ -305,7 +305,7 @@ trait CompilerInterface { /** Tree representing a selection of definition with a given name on a given prefix */ type Select <: Ref - def matchSelect(tree: Tree)(given ctx: Context): Option[Select] + def isInstanceOfSelect(given ctx: Context): IsInstanceOf[Select] def Select_qualifier(self: Select)(given ctx: Context): Term def Select_name(self: Select)(given ctx: Context): String @@ -320,7 +320,7 @@ trait CompilerInterface { /** Tree representing a literal value in the source code */ type Literal <: Term - def matchLiteral(tree: Tree)(given ctx: Context): Option[Literal] + def isInstanceOfLiteral(given ctx: Context): IsInstanceOf[Literal] def Literal_constant(self: Literal)(given ctx: Context): Constant @@ -330,7 +330,7 @@ trait CompilerInterface { /** Tree representing `this` in the source code */ type This <: Term - def matchThis(tree: Tree)(given ctx: Context): Option[This] + def isInstanceOfThis(given ctx: Context): IsInstanceOf[This] def This_id(self: This)(given ctx: Context): Option[Id] @@ -340,7 +340,7 @@ trait CompilerInterface { /** Tree representing `new` in the source code */ type New <: Term - def matchNew(tree: Tree)(given ctx: Context): Option[New] + def isInstanceOfNew(given ctx: Context): IsInstanceOf[New] def New_tpt(self: New)(given ctx: Context): TypeTree @@ -350,7 +350,7 @@ trait CompilerInterface { /** Tree representing an argument passed with an explicit name. Such as `arg1 = x` in `foo(arg1 = x)` */ type NamedArg <: Term - def matchNamedArg(tree: Tree)(given ctx: Context): Option[NamedArg] + def isInstanceOfNamedArg(given ctx: Context): IsInstanceOf[NamedArg] def NamedArg_name(self: NamedArg)(given ctx: Context): String def NamedArg_value(self: NamedArg)(given ctx: Context): Term @@ -361,7 +361,7 @@ trait CompilerInterface { /** Tree an application of arguments. It represents a single list of arguments, multiple argument lists will have nested `Apply`s */ type Apply <: Term - def matchApply(tree: Tree)(given ctx: Context): Option[Apply] + def isInstanceOfApply(given ctx: Context): IsInstanceOf[Apply] def Apply_fun(self: Apply)(given ctx: Context): Term def Apply_args(self: Apply)(given ctx: Context): List[Term] @@ -372,7 +372,7 @@ trait CompilerInterface { /** Tree an application of type arguments */ type TypeApply <: Term - def matchTypeApply(tree: Tree)(given ctx: Context): Option[TypeApply] + def isInstanceOfTypeApply(given ctx: Context): IsInstanceOf[TypeApply] def TypeApply_fun(self: TypeApply)(given ctx: Context): Term def TypeApply_args(self: TypeApply)(given ctx: Context): List[TypeTree] @@ -383,7 +383,7 @@ trait CompilerInterface { /** Tree representing `super` in the source code */ type Super <: Term - def matchSuper(tree: Tree)(given ctx: Context): Option[Super] + def isInstanceOfSuper(given ctx: Context): IsInstanceOf[Super] def Super_qualifier(self: Super)(given ctx: Context): Term def Super_id(self: Super)(given ctx: Context): Option[Id] @@ -394,7 +394,7 @@ trait CompilerInterface { /** Tree representing a type ascription `x: T` in the source code */ type Typed <: Term - def matchTyped(tree: Tree)(given ctx: Context): Option[Typed] + def isInstanceOfTyped(given ctx: Context): IsInstanceOf[Typed] def Typed_expr(self: Typed)(given ctx: Context): Term def Typed_tpt(self: Typed)(given ctx: Context): TypeTree @@ -405,7 +405,7 @@ trait CompilerInterface { /** Tree representing an assignment `x = y` in the source code */ type Assign <: Term - def matchAssign(tree: Tree)(given ctx: Context): Option[Assign] + def isInstanceOfAssign(given ctx: Context): IsInstanceOf[Assign] def Assign_lhs(self: Assign)(given ctx: Context): Term def Assign_rhs(self: Assign)(given ctx: Context): Term @@ -416,7 +416,7 @@ trait CompilerInterface { /** Tree representing a block `{ ... }` in the source code */ type Block <: Term - def matchBlock(tree: Tree)(given ctx: Context): Option[Block] + def isInstanceOfBlock(given ctx: Context): IsInstanceOf[Block] def Block_statements(self: Block)(given ctx: Context): List[Statement] def Block_expr(self: Block)(given ctx: Context): Term @@ -435,7 +435,7 @@ trait CompilerInterface { */ type Closure <: Term - def matchClosure(tree: Tree)(given ctx: Context): Option[Closure] + def isInstanceOfClosure(given ctx: Context): IsInstanceOf[Closure] def Closure_meth(self: Closure)(given ctx: Context): Term def Closure_tpeOpt(self: Closure)(given ctx: Context): Option[Type] @@ -446,7 +446,7 @@ trait CompilerInterface { /** Tree representing an if/then/else `if (...) ... else ...` in the source code */ type If <: Term - def matchIf(tree: Tree)(given ctx: Context): Option[If] + def isInstanceOfIf(given ctx: Context): IsInstanceOf[If] def If_cond(self: If)(given ctx: Context): Term def If_thenp(self: If)(given ctx: Context): Term @@ -458,7 +458,7 @@ trait CompilerInterface { /** Tree representing a pattern match `x match { ... }` in the source code */ type Match <: Term - def matchMatch(tree: Tree)(given ctx: Context): Option[Match] + def isInstanceOfMatch(given ctx: Context): IsInstanceOf[Match] def Match_scrutinee(self: Match)(given ctx: Context): Term def Match_cases(self: Match)(given ctx: Context): List[CaseDef] @@ -469,7 +469,7 @@ trait CompilerInterface { /** Tree representing a pattern match `delegate match { ... }` in the source code */ type ImpliedMatch <: Term - def matchImplicitMatch(tree: Tree)(given ctx: Context): Option[ImpliedMatch] + def isInstanceOfImpliedMatch(given ctx: Context): IsInstanceOf[ImpliedMatch] def ImplicitMatch_cases(self: ImpliedMatch)(given ctx: Context): List[CaseDef] @@ -479,7 +479,7 @@ trait CompilerInterface { /** Tree representing a tyr catch `try x catch { ... } finally { ... }` in the source code */ type Try <: Term - def matchTry(tree: Tree)(given ctx: Context): Option[Try] + def isInstanceOfTry(given ctx: Context): IsInstanceOf[Try] def Try_body(self: Try)(given ctx: Context): Term def Try_cases(self: Try)(given ctx: Context): List[CaseDef] @@ -491,7 +491,7 @@ trait CompilerInterface { /** Tree representing a `return` in the source code */ type Return <: Term - def matchReturn(tree: Tree)(given ctx: Context): Option[Return] + def isInstanceOfReturn(given ctx: Context): IsInstanceOf[Return] def Return_expr(self: Return)(given ctx: Context): Term @@ -501,7 +501,7 @@ trait CompilerInterface { /** Tree representing a variable argument list in the source code */ type Repeated <: Term - def matchRepeated(tree: Tree)(given ctx: Context): Option[Repeated] + def isInstanceOfRepeated(given ctx: Context): IsInstanceOf[Repeated] def Repeated_elems(self: Repeated)(given ctx: Context): List[Term] def Repeated_elemtpt(self: Repeated)(given ctx: Context): TypeTree @@ -512,7 +512,7 @@ trait CompilerInterface { /** Tree representing the scope of an inlined tree */ type Inlined <: Term - def matchInlined(tree: Tree)(given ctx: Context): Option[Inlined] + def isInstanceOfInlined(given ctx: Context): IsInstanceOf[Inlined] def Inlined_call(self: Inlined)(given ctx: Context): Option[Tree/* Term | TypeTree */] def Inlined_bindings(self: Inlined)(given ctx: Context): List[Definition] @@ -524,7 +524,7 @@ trait CompilerInterface { /** Tree representing a selection of definition with a given name on a given prefix and number of nested scopes of inlined trees */ type SelectOuter <: Term - def matchSelectOuter(tree: Tree)(given ctx: Context): Option[SelectOuter] + def isInstanceOfSelectOuter(given ctx: Context): IsInstanceOf[SelectOuter] def SelectOuter_qualifier(self: SelectOuter)(given ctx: Context): Term def SelectOuter_level(self: SelectOuter)(given ctx: Context): Int @@ -535,7 +535,7 @@ trait CompilerInterface { /** Tree representing a while loop */ type While <: Term - def matchWhile(tree: Tree)(given ctx: Context): Option[While] + def isInstanceOfWhile(given ctx: Context): IsInstanceOf[While] def While_cond(self: While)(given ctx: Context): Term def While_body(self: While)(given ctx: Context): Term @@ -546,21 +546,21 @@ trait CompilerInterface { /** Type tree representing a type written in the source */ type TypeTree <: Tree - def matchTypeTree(tree: Tree)(given ctx: Context): Option[TypeTree] + def isInstanceOfTypeTree(given ctx: Context): IsInstanceOf[TypeTree] def TypeTree_tpe(self: TypeTree)(given ctx: Context): Type /** Type tree representing an inferred type */ type Inferred <: TypeTree - def matchInferred(tree: Tree)(given ctx: Context): Option[Inferred] + def isInstanceOfInferred(given ctx: Context): IsInstanceOf[Inferred] def Inferred_apply(tpe: Type)(given ctx: Context): Inferred /** Type tree representing a reference to definition with a given name */ type TypeIdent <: TypeTree - def matchTypeIdent(tree: Tree)(given ctx: Context): Option[TypeIdent] + def isInstanceOfTypeIdent(given ctx: Context): IsInstanceOf[TypeIdent] def TypeIdent_name(self: TypeIdent)(given ctx: Context): String @@ -569,7 +569,7 @@ trait CompilerInterface { /** Type tree representing a selection of definition with a given name on a given term prefix */ type TypeSelect <: TypeTree - def matchTypeSelect(tree: Tree)(given ctx: Context): Option[TypeSelect] + def isInstanceOfTypeSelect(given ctx: Context): IsInstanceOf[TypeSelect] def TypeSelect_qualifier(self: TypeSelect)(given ctx: Context): Term def TypeSelect_name(self: TypeSelect)(given ctx: Context): String @@ -580,7 +580,7 @@ trait CompilerInterface { /** Type tree representing a selection of definition with a given name on a given type prefix */ type Projection <: TypeTree - def matchProjection(tree: Tree)(given ctx: Context): Option[Projection] + def isInstanceOfProjection(given ctx: Context): IsInstanceOf[Projection] def Projection_qualifier(self: Projection)(given ctx: Context): TypeTree def Projection_name(self: Projection)(given ctx: Context): String @@ -590,7 +590,7 @@ trait CompilerInterface { /** Type tree representing a singleton type */ type Singleton <: TypeTree - def matchSingleton(tree: Tree)(given ctx: Context): Option[Singleton] + def isInstanceOfSingleton(given ctx: Context): IsInstanceOf[Singleton] def Singleton_ref(self: Singleton)(given ctx: Context): Term @@ -600,7 +600,7 @@ trait CompilerInterface { /** Type tree representing a type refinement */ type Refined <: TypeTree - def matchRefined(tree: Tree)(given ctx: Context): Option[Refined] + def isInstanceOfRefined(given ctx: Context): IsInstanceOf[Refined] def Refined_tpt(self: Refined)(given ctx: Context): TypeTree def Refined_refinements(self: Refined)(given ctx: Context): List[Definition] @@ -610,7 +610,7 @@ trait CompilerInterface { /** Type tree representing a type application */ type Applied <: TypeTree - def matchApplied(tree: Tree)(given ctx: Context): Option[Applied] + def isInstanceOfApplied(given ctx: Context): IsInstanceOf[Applied] def Applied_tpt(self: Applied)(given ctx: Context): TypeTree def Applied_args(self: Applied)(given ctx: Context): List[Tree /*TypeTree | TypeBoundsTree*/] @@ -621,7 +621,7 @@ trait CompilerInterface { /** Type tree representing an annotated type */ type Annotated <: TypeTree - def matchAnnotated(tree: Tree)(given ctx: Context): Option[Annotated] + def isInstanceOfAnnotated(given ctx: Context): IsInstanceOf[Annotated] def Annotated_arg(self: Annotated)(given ctx: Context): TypeTree def Annotated_annotation(self: Annotated)(given ctx: Context): Term @@ -632,7 +632,7 @@ trait CompilerInterface { /** Type tree representing a type match */ type MatchTypeTree <: TypeTree - def matchMatchTypeTree(tree: Tree)(given ctx: Context): Option[MatchTypeTree] + def isInstanceOfMatchTypeTree(given ctx: Context): IsInstanceOf[MatchTypeTree] def MatchTypeTree_bound(self: MatchTypeTree)(given ctx: Context): Option[TypeTree] def MatchTypeTree_selector(self: MatchTypeTree)(given ctx: Context): TypeTree @@ -646,7 +646,7 @@ trait CompilerInterface { def ByName_result(self: ByName)(given ctx: Context): TypeTree - def matchByName(tree: Tree)(given ctx: Context): Option[ByName] + def isInstanceOfByName(given ctx: Context): IsInstanceOf[ByName] def ByName_apply(result: TypeTree)(given ctx: Context): ByName def ByName_copy(original: Tree)(result: TypeTree)(given ctx: Context): ByName @@ -654,7 +654,7 @@ trait CompilerInterface { /** Type tree representing a lambda abstraction type */ type LambdaTypeTree <: TypeTree - def matchLambdaTypeTree(tree: Tree)(given ctx: Context): Option[LambdaTypeTree] + def isInstanceOfLambdaTypeTree(given ctx: Context): IsInstanceOf[LambdaTypeTree] def Lambdatparams(self: LambdaTypeTree)(given ctx: Context): List[TypeDef] def Lambdabody(self: LambdaTypeTree)(given ctx: Context): Tree /*TypeTree | TypeBoundsTree*/ @@ -665,7 +665,7 @@ trait CompilerInterface { /** Type tree representing a type binding */ type TypeBind <: TypeTree - def matchTypeBind(tree: Tree)(given ctx: Context): Option[TypeBind] + def isInstanceOfTypeBind(given ctx: Context): IsInstanceOf[TypeBind] def TypeBind_name(self: TypeBind)(given ctx: Context): String def TypeBind_body(self: TypeBind)(given ctx: Context): Tree /*TypeTree | TypeBoundsTree*/ @@ -675,7 +675,7 @@ trait CompilerInterface { /** Type tree within a block with aliases `{ type U1 = ... ; T[U1, U2] }` */ type TypeBlock <: TypeTree - def matchTypeBlock(tree: Tree)(given ctx: Context): Option[TypeBlock] + def isInstanceOfTypeBlock(given ctx: Context): IsInstanceOf[TypeBlock] def TypeBlock_aliases(self: TypeBlock)(given ctx: Context): List[TypeDef] def TypeBlock_tpt(self: TypeBlock)(given ctx: Context): TypeTree @@ -686,7 +686,7 @@ trait CompilerInterface { /** Type tree representing a type bound written in the source */ type TypeBoundsTree <: Tree /*TypeTree | TypeBoundsTree*/ - def matchTypeBoundsTree(tree: Tree)(given ctx: Context): Option[TypeBoundsTree] + def isInstanceOfTypeBoundsTree(given ctx: Context): IsInstanceOf[TypeBoundsTree] def TypeBoundsTree_tpe(self: TypeBoundsTree)(given ctx: Context): TypeBounds def TypeBoundsTree_low(self: TypeBoundsTree)(given ctx: Context): TypeTree @@ -698,14 +698,14 @@ trait CompilerInterface { */ type WildcardTypeTree <: Tree - def matchWildcardTypeTree(tree: Tree)(given ctx: Context): Option[WildcardTypeTree] + def isInstanceOfWildcardTypeTree(given ctx: Context): IsInstanceOf[WildcardTypeTree] def WildcardTypeTree_tpe(self: WildcardTypeTree)(given ctx: Context): TypeOrBounds /** Branch of a pattern match or catch clause */ type CaseDef <: Tree - def matchCaseDef(tree: Tree)(given ctx: Context): Option[CaseDef] + def isInstanceOfCaseDef(given ctx: Context): IsInstanceOf[CaseDef] def CaseDef_pattern(self: CaseDef)(given ctx: Context): Tree def CaseDef_guard(self: CaseDef)(given ctx: Context): Option[Term] @@ -717,7 +717,7 @@ trait CompilerInterface { /** Branch of a type pattern match */ type TypeCaseDef <: Tree - def matchTypeCaseDef(tree: Tree)(given ctx: Context): Option[TypeCaseDef] + def isInstanceOfTypeCaseDef(given ctx: Context): IsInstanceOf[TypeCaseDef] def TypeCaseDef_pattern(self: TypeCaseDef)(given ctx: Context): TypeTree def TypeCaseDef_rhs(self: TypeCaseDef)(given ctx: Context): TypeTree @@ -732,7 +732,7 @@ trait CompilerInterface { /** Tree representing a binding pattern `_ @ _` */ type Bind <: Tree - def matchTree_Bind(x: Tree)(given ctx: Context): Option[Bind] + def isInstanceOfBind(given ctx: Context): IsInstanceOf[Bind] def Tree_Bind_name(self: Bind)(given ctx: Context): String @@ -743,7 +743,7 @@ trait CompilerInterface { /** Tree representing an unapply pattern `Xyz(...)` */ type Unapply <: Tree - def matchTree_Unapply(pattern: Tree)(given ctx: Context): Option[Unapply] + def isInstanceOfUnapply(given ctx: Context): IsInstanceOf[Unapply] def Tree_Unapply_fun(self: Unapply)(given ctx: Context): Term @@ -756,7 +756,7 @@ trait CompilerInterface { /** Tree representing pattern alternatives `X | Y | ...` */ type Alternatives <: Tree - def matchTree_Alternatives(pattern: Tree)(given ctx: Context): Option[Alternatives] + def isInstanceOfAlternatives(given ctx: Context): IsInstanceOf[Alternatives] def Tree_Alternatives_patterns(self: Alternatives)(given ctx: Context): List[Tree] @@ -774,12 +774,12 @@ trait CompilerInterface { /** NoPrefix for a type selection */ type NoPrefix <: TypeOrBounds - def matchNoPrefix(x: TypeOrBounds)(given ctx: Context): Option[NoPrefix] + def isInstanceOfNoPrefix(given ctx: Context): IsInstanceOf[NoPrefix] /** Type bounds */ type TypeBounds <: TypeOrBounds - def matchTypeBounds(x: TypeOrBounds)(given ctx: Context): Option[TypeBounds] + def isInstanceOfTypeBounds(given ctx: Context): IsInstanceOf[TypeBounds] def TypeBounds_low(self: TypeBounds)(given ctx: Context): Type def TypeBounds_hi(self: TypeBounds)(given ctx: Context): Type @@ -787,7 +787,7 @@ trait CompilerInterface { /** A type */ type Type <: TypeOrBounds - def matchType(x: TypeOrBounds)(given ctx: Context): Option[Type] + def isInstanceOfType(given ctx: Context): IsInstanceOf[Type] def Type_apply(clazz: Class[_])(given ctx: Context): Type @@ -859,14 +859,14 @@ trait CompilerInterface { /** A singleton type representing a known constant value */ type ConstantType <: Type - def matchConstantType(tpe: TypeOrBounds)(given ctx: Context): Option[ConstantType] + def isInstanceOfConstantType(given ctx: Context): IsInstanceOf[ConstantType] def ConstantType_constant(self: ConstantType)(given ctx: Context): Constant /** Type of a reference to a term symbol */ type TermRef <: Type - def matchTermRef(tpe: TypeOrBounds)(given ctx: Context): Option[TermRef] + def isInstanceOfTermRef(given ctx: Context): IsInstanceOf[TermRef] def TermRef_apply(qual: TypeOrBounds, name: String)(given ctx: Context): TermRef @@ -876,7 +876,7 @@ trait CompilerInterface { /** Type of a reference to a type symbol */ type TypeRef <: Type - def matchTypeRef(tpe: TypeOrBounds)(given ctx: Context): Option[TypeRef] + def isInstanceOfTypeRef(given ctx: Context): IsInstanceOf[TypeRef] def TypeRef_qualifier(self: TypeRef)(given ctx: Context): TypeOrBounds def TypeRef_name(self: TypeRef)(given Context): String @@ -884,7 +884,7 @@ trait CompilerInterface { /** Type of a `super` refernce */ type SuperType <: Type - def matchSuperType(tpe: TypeOrBounds)(given ctx: Context): Option[SuperType] + def isInstanceOfSuperType(given ctx: Context): IsInstanceOf[SuperType] def SuperType_thistpe(self: SuperType)(given ctx: Context): Type def SuperType_supertpe(self: SuperType)(given ctx: Context): Type @@ -892,7 +892,7 @@ trait CompilerInterface { /** A type with a type refinement `T { type U }` */ type Refinement <: Type - def matchRefinement(tpe: TypeOrBounds)(given ctx: Context): Option[Refinement] + def isInstanceOfRefinement(given ctx: Context): IsInstanceOf[Refinement] def Refinement_parent(self: Refinement)(given ctx: Context): Type def Refinement_name(self: Refinement)(given ctx: Context): String @@ -901,7 +901,7 @@ trait CompilerInterface { /** A higher kinded type applied to some types `T[U]` */ type AppliedType <: Type - def matchAppliedType(tpe: TypeOrBounds)(given ctx: Context): Option[AppliedType] + def isInstanceOfAppliedType(given ctx: Context): IsInstanceOf[AppliedType] def AppliedType_tycon(self: AppliedType)(given ctx: Context): Type def AppliedType_args(self: AppliedType)(given ctx: Context): List[TypeOrBounds] @@ -911,7 +911,7 @@ trait CompilerInterface { /** A type with an anottation `T @foo` */ type AnnotatedType <: Type - def matchAnnotatedType(tpe: TypeOrBounds)(given ctx: Context): Option[AnnotatedType] + def isInstanceOfAnnotatedType(given ctx: Context): IsInstanceOf[AnnotatedType] def AnnotatedType_underlying(self: AnnotatedType)(given ctx: Context): Type def AnnotatedType_annot(self: AnnotatedType)(given ctx: Context): Term @@ -919,7 +919,7 @@ trait CompilerInterface { /** Intersection type `T & U` */ type AndType <: Type - def matchAndType(tpe: TypeOrBounds)(given ctx: Context): Option[AndType] + def isInstanceOfAndType(given ctx: Context): IsInstanceOf[AndType] def AndType_left(self: AndType)(given ctx: Context): Type def AndType_right(self: AndType)(given ctx: Context): Type @@ -927,7 +927,7 @@ trait CompilerInterface { /** Union type `T | U` */ type OrType <: Type - def matchOrType(tpe: TypeOrBounds)(given ctx: Context): Option[OrType] + def isInstanceOfOrType(given ctx: Context): IsInstanceOf[OrType] def OrType_left(self: OrType)(given ctx: Context): Type def OrType_right(self: OrType)(given ctx: Context): Type @@ -935,7 +935,7 @@ trait CompilerInterface { /** Type match `T match { case U => ... }` */ type MatchType <: Type - def matchMatchType(tpe: TypeOrBounds)(given ctx: Context): Option[MatchType] + def isInstanceOfMatchType(given ctx: Context): IsInstanceOf[MatchType] def MatchType_bound(self: MatchType)(given ctx: Context): Type def MatchType_scrutinee(self: MatchType)(given ctx: Context): Type @@ -944,14 +944,14 @@ trait CompilerInterface { /** Type of a by by name parameter */ type ByNameType <: Type - def matchByNameType(tpe: TypeOrBounds)(given ctx: Context): Option[ByNameType] + def isInstanceOfByNameType(given ctx: Context): IsInstanceOf[ByNameType] def ByNameType_underlying(self: ByNameType)(given ctx: Context): Type /** Type of a parameter reference */ type ParamRef <: Type - def matchParamRef(tpe: TypeOrBounds)(given ctx: Context): Option[ParamRef] + def isInstanceOfParamRef(given ctx: Context): IsInstanceOf[ParamRef] def ParamRef_binder(self: ParamRef)(given ctx: Context): LambdaType[TypeOrBounds] def ParamRef_paramNum(self: ParamRef)(given ctx: Context): Int @@ -959,21 +959,21 @@ trait CompilerInterface { /** Type of `this` */ type ThisType <: Type - def matchThisType(tpe: TypeOrBounds)(given ctx: Context): Option[ThisType] + def isInstanceOfThisType(given ctx: Context): IsInstanceOf[ThisType] def ThisType_tref(self: ThisType)(given ctx: Context): Type /** A type that is recursively defined `this` */ type RecursiveThis <: Type - def matchRecursiveThis(tpe: TypeOrBounds)(given ctx: Context): Option[RecursiveThis] + def isInstanceOfRecursiveThis(given ctx: Context): IsInstanceOf[RecursiveThis] def RecursiveThis_binder(self: RecursiveThis)(given ctx: Context): RecursiveType /** A type that is recursively defined */ type RecursiveType <: Type - def matchRecursiveType(tpe: TypeOrBounds)(given ctx: Context): Option[RecursiveType] + def isInstanceOfRecursiveType(given ctx: Context): IsInstanceOf[RecursiveType] def RecursiveType_underlying(self: RecursiveType)(given ctx: Context): Type @@ -985,7 +985,7 @@ trait CompilerInterface { /** Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType. */ type MethodType <: LambdaType[Type] - def matchMethodType(tpe: TypeOrBounds)(given ctx: Context): Option[MethodType] + def isInstanceOfMethodType(given ctx: Context): IsInstanceOf[MethodType] def MethodType_isErased(self: MethodType): Boolean def MethodType_isImplicit(self: MethodType): Boolean @@ -996,7 +996,7 @@ trait CompilerInterface { /** Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType. */ type PolyType <: LambdaType[TypeBounds] - def matchPolyType(tpe: TypeOrBounds)(given ctx: Context): Option[PolyType] + def isInstanceOfPolyType(given ctx: Context): IsInstanceOf[PolyType] def PolyType_paramNames(self: PolyType)(given ctx: Context): List[String] def PolyType_paramBounds(self: PolyType)(given ctx: Context): List[TypeBounds] @@ -1005,7 +1005,7 @@ trait CompilerInterface { /** Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda. */ type TypeLambda <: LambdaType[TypeBounds] - def matchTypeLambda(tpe: TypeOrBounds)(given ctx: Context): Option[TypeLambda] + def isInstanceOfTypeLambda(given ctx: Context): IsInstanceOf[TypeLambda] def TypeLambda_paramNames(self: TypeLambda)(given ctx: Context): List[String] def TypeLambda_paramBounds(self: TypeLambda)(given ctx: Context): List[TypeBounds] @@ -1024,20 +1024,20 @@ trait CompilerInterface { type SimpleSelector <: ImportSelector - def matchSimpleSelector(self: ImportSelector)(given ctx: Context): Option[SimpleSelector] + def isInstanceOfSimpleSelector(given ctx: Context): IsInstanceOf[SimpleSelector] def SimpleSelector_selection(self: SimpleSelector)(given ctx: Context): Id type RenameSelector <: ImportSelector - def matchRenameSelector(self: ImportSelector)(given ctx: Context): Option[RenameSelector] + def isInstanceOfRenameSelector(given ctx: Context): IsInstanceOf[RenameSelector] def RenameSelector_from(self: RenameSelector)(given ctx: Context): Id def RenameSelector_to(self: RenameSelector)(given ctx: Context): Id type OmitSelector <: ImportSelector - def matchOmitSelector(self: ImportSelector)(given ctx: Context): Option[OmitSelector] + def isInstanceOfOmitSelector(given ctx: Context): IsInstanceOf[OmitSelector] def SimpleSelector_omitted(self: OmitSelector)(given ctx: Context): Id @@ -1414,21 +1414,21 @@ trait CompilerInterface { type ImplicitSearchResult <: AnyRef type ImplicitSearchSuccess <: ImplicitSearchResult - def matchImplicitSearchSuccess(isr: ImplicitSearchResult)(given ctx: Context): Option[ImplicitSearchSuccess] + def isInstanceOfImplicitSearchSuccess(given ctx: Context): IsInstanceOf[ImplicitSearchSuccess] def ImplicitSearchSuccess_tree(self: ImplicitSearchSuccess)(given ctx: Context): Term type ImplicitSearchFailure <: ImplicitSearchResult - def matchImplicitSearchFailure(isr: ImplicitSearchResult)(given ctx: Context): Option[ImplicitSearchFailure] + def isInstanceOfImplicitSearchFailure(given ctx: Context): IsInstanceOf[ImplicitSearchFailure] def ImplicitSearchFailure_explanation(self: ImplicitSearchFailure)(given ctx: Context): String type DivergingImplicit <: ImplicitSearchFailure - def matchDivergingImplicit(isr: ImplicitSearchResult)(given ctx: Context): Option[DivergingImplicit] + def isInstanceOfDivergingImplicit(given ctx: Context): IsInstanceOf[DivergingImplicit] type NoMatchingImplicits <: ImplicitSearchFailure - def matchNoMatchingImplicits(isr: ImplicitSearchResult)(given ctx: Context): Option[NoMatchingImplicits] + def isInstanceOfNoMatchingImplicits(given ctx: Context): IsInstanceOf[NoMatchingImplicits] type AmbiguousImplicits <: ImplicitSearchFailure - def matchAmbiguousImplicits(isr: ImplicitSearchResult)(given ctx: Context): Option[AmbiguousImplicits] + def isInstanceOfAmbiguousImplicits(given ctx: Context): IsInstanceOf[AmbiguousImplicits] /** Find an implicit of type `T` in the current scope given by `ctx`. * Return an `ImplicitSearchResult`. diff --git a/library/src/scala/tasty/reflect/ImplicitsOps.scala b/library/src/scala/tasty/reflect/ImplicitsOps.scala index a274572d6b98..335941ac8e87 100644 --- a/library/src/scala/tasty/reflect/ImplicitsOps.scala +++ b/library/src/scala/tasty/reflect/ImplicitsOps.scala @@ -5,37 +5,42 @@ trait ImplicitsOps extends Core { def searchImplicit(tpe: Type)(given ctx: Context): ImplicitSearchResult = internal.searchImplicit(tpe) - object IsImplicitSearchSuccess { - def unapply(isr: ImplicitSearchResult)(given ctx: Context): Option[ImplicitSearchSuccess] = - internal.matchImplicitSearchSuccess(isr) - } + given (given Context): IsInstanceOf[ImplicitSearchSuccess] = internal.isInstanceOfImplicitSearchSuccess + + object IsImplicitSearchSuccess + @deprecated("Use _: ImplicitSearchSuccess", "") + def unapply(isr: ImplicitSearchSuccess)(given ctx: Context): Option[ImplicitSearchSuccess] = Some(isr) given SuccessOps: (self: ImplicitSearchSuccess) { def tree(given ctx: Context): Term = internal.ImplicitSearchSuccess_tree(self) } - object IsImplicitSearchFailure { - def unapply(isr: ImplicitSearchResult)(given ctx: Context): Option[ImplicitSearchFailure] = - internal.matchImplicitSearchFailure(isr) - } + given (given Context): IsInstanceOf[ImplicitSearchFailure] = internal.isInstanceOfImplicitSearchFailure + + object IsImplicitSearchFailure + @deprecated("Use _: ImplicitSearchFailure", "") + def unapply(isr: ImplicitSearchFailure)(given ctx: Context): Option[ImplicitSearchFailure] = Some(isr) given FailureOps: (self: ImplicitSearchFailure) { def explanation(given ctx: Context): String = internal.ImplicitSearchFailure_explanation(self) } - object IsDivergingImplicit { - def unapply(isr: ImplicitSearchResult)(given ctx: Context): Option[DivergingImplicit] = - internal.matchDivergingImplicit(isr) - } + given (given Context): IsInstanceOf[DivergingImplicit] = internal.isInstanceOfDivergingImplicit - object IsNoMatchingImplicits { - def unapply(isr: ImplicitSearchResult)(given ctx: Context): Option[NoMatchingImplicits] = - internal.matchNoMatchingImplicits(isr) - } + object IsDivergingImplicit + @deprecated("Use _: DivergingImplicit", "") + def unapply(isr: DivergingImplicit)(given ctx: Context): Option[DivergingImplicit] = Some(isr) - object IsAmbiguousImplicits { - def unapply(isr: ImplicitSearchResult)(given ctx: Context): Option[AmbiguousImplicits] = - internal.matchAmbiguousImplicits(isr) - } + given (given Context): IsInstanceOf[NoMatchingImplicits] = internal.isInstanceOfNoMatchingImplicits + + object IsNoMatchingImplicits + @deprecated("Use _: NoMatchingImplicits", "") + def unapply(isr: NoMatchingImplicits)(given ctx: Context): Option[NoMatchingImplicits] = Some(isr) + + given (given Context): IsInstanceOf[AmbiguousImplicits] = internal.isInstanceOfAmbiguousImplicits + + object IsAmbiguousImplicits + @deprecated("Use _: AmbiguousImplicits", "") + def unapply(isr: AmbiguousImplicits)(given ctx: Context): Option[AmbiguousImplicits] = Some(isr) } diff --git a/library/src/scala/tasty/reflect/ImportSelectorOps.scala b/library/src/scala/tasty/reflect/ImportSelectorOps.scala index 9b4d4460409c..c955d3b082f0 100644 --- a/library/src/scala/tasty/reflect/ImportSelectorOps.scala +++ b/library/src/scala/tasty/reflect/ImportSelectorOps.scala @@ -8,10 +8,10 @@ trait ImportSelectorOps extends Core { internal.SimpleSelector_selection(self) } - object SimpleSelector { - def unapply(importSelector: ImportSelector)(given ctx: Context): Option[Id] = - internal.matchSimpleSelector(importSelector).map(_.selection) - } + given (given Context): IsInstanceOf[SimpleSelector] = internal.isInstanceOfSimpleSelector + + object SimpleSelector + def unapply(x: SimpleSelector)(given ctx: Context): Option[Id] = Some(x.selection) given RenameSelectorOps: (self: RenameSelector) { def from(given ctx: Context): Id = @@ -21,19 +21,19 @@ trait ImportSelectorOps extends Core { internal.RenameSelector_to(self) } - object RenameSelector { - def unapply(importSelector: ImportSelector)(given ctx: Context): Option[(Id, Id)] = - internal.matchRenameSelector(importSelector).map(x => (x.from, x.to)) - } + given (given Context): IsInstanceOf[RenameSelector] = internal.isInstanceOfRenameSelector + + object RenameSelector + def unapply(x: RenameSelector)(given ctx: Context): Option[(Id, Id)] = Some((x.from, x.to)) given OmitSelectorOps: (self: OmitSelector) { def omitted(given ctx: Context): Id = internal.SimpleSelector_omitted(self) } - object OmitSelector { - def unapply(importSelector: ImportSelector)(given ctx: Context): Option[Id] = - internal.matchOmitSelector(importSelector).map(_.omitted) - } + given (given Context): IsInstanceOf[OmitSelector] = internal.isInstanceOfOmitSelector + + object OmitSelector + def unapply(x: OmitSelector)(given ctx: Context): Option[Id] = Some(x.omitted) } diff --git a/library/src/scala/tasty/reflect/IsInstanceOf.scala b/library/src/scala/tasty/reflect/IsInstanceOf.scala new file mode 100644 index 000000000000..ea1ca85e6f6e --- /dev/null +++ b/library/src/scala/tasty/reflect/IsInstanceOf.scala @@ -0,0 +1,39 @@ +package scala.tasty +package reflect +/* FIXME Using class tags to type tests abstract type members in unsound + + ``` + trait R { + type Nat + type Succ <: Nat + type Idx + given ClassTag[Nat] + given ClassTag[Succ] + given ClassTag[Idx] + def n: Nat + } + object RI extens R { + type Nat = Int + type Succ = Int + type Idx = Int + given ClassTag[Nat] = classOf[Integer] + given ClassTag[Succ] = new ClassTag[Integer] { + def runtimeClass = classOf[Integer] + def unapply(x: Any): Option[Succ] = x match + case n: Int if n > 0 => Some(n) + case _ => None + } + given ClassTag[Idx] = classOf[Integer] + def n: Nat = 4 + } + val r1: R = RI + val r2: R = RI + r1.n match { + case n: r2.Nat => // Should not match or should have an unchecked waring + case n: r1.Idx => // Should not match or should have an unchecked waring + case n: r1.Succ => // Should match only if r1.n is an r1.Succ under the constraints set in r1 + } + ``` +*/ +/** Place holder until we implement a ClassTag like abstraction that is sound for all type tests */ +type IsInstanceOf[T] = scala.reflect.ClassTag[T] diff --git a/library/src/scala/tasty/reflect/SourceCodePrinter.scala b/library/src/scala/tasty/reflect/SourceCodePrinter.scala index 767ac4d2b461..f8587ad8d829 100644 --- a/library/src/scala/tasty/reflect/SourceCodePrinter.scala +++ b/library/src/scala/tasty/reflect/SourceCodePrinter.scala @@ -105,8 +105,8 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig case tree @ PackageClause(name, stats) => val stats1 = stats.collect { - case IsPackageClause(stat) => stat - case IsDefinition(stat) if !(stat.symbol.flags.is(Flags.Object) && stat.symbol.flags.is(Flags.Lazy)) => stat + case stat: PackageClause => stat + case stat: Definition if !(stat.symbol.flags.is(Flags.Object) && stat.symbol.flags.is(Flags.Lazy)) => stat case stat @ Import(_, _) => stat } name match { @@ -124,7 +124,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig this += "." printImportSelectors(selectors) - case IsClassDef(cdef @ ClassDef(name, DefDef(_, targs, argss, _, _), parents, derived, self, stats)) => + case cdef @ ClassDef(name, DefDef(_, targs, argss, _, _), parents, derived, self, stats) => printDefAnnotations(cdef) val flags = cdef.symbol.flags @@ -141,7 +141,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig else if (flags.is(Flags.Abstract)) this += highlightKeyword("abstract class ") += highlightTypeDef(name) else this += highlightKeyword("class ") += highlightTypeDef(name) - val typeParams = stats.collect { case IsTypeDef(targ) => targ }.filter(_.symbol.isTypeParam).zip(targs) + val typeParams = stats.collect { case targ: TypeDef => targ }.filter(_.symbol.isTypeParam).zip(targs) if (!flags.is(Flags.Object)) { printTargsDefs(typeParams) val it = argss.iterator @@ -150,30 +150,30 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig } val parents1 = parents.filter { - case IsTerm(Apply(Select(New(tpt), _), _)) => !Types.JavaLangObject.unapply(tpt.tpe) - case IsTypeTree(TypeSelect(Select(Ident("_root_"), "scala"), "Product")) => false - case IsTypeTree(TypeSelect(Select(Ident("_root_"), "scala"), "Serializable")) => false + case Apply(Select(New(tpt), _), _) => !Types.JavaLangObject.unapply(tpt.tpe) + case TypeSelect(Select(Ident("_root_"), "scala"), "Product") => false + case TypeSelect(Select(Ident("_root_"), "scala"), "Serializable") => false case _ => true } if (parents1.nonEmpty) this += highlightKeyword(" extends ") def printParent(parent: Tree /* Term | TypeTree */, needEmptyParens: Boolean = false): Unit = parent match { - case IsTypeTree(parent) => + case parent: TypeTree => printTypeTree(parent)(given Some(cdef.symbol)) - case IsTerm(TypeApply(fun, targs)) => + case TypeApply(fun, targs) => printParent(fun) - case IsTerm(Apply(fun@Apply(_,_), args)) => + case Apply(fun@Apply(_,_), args) => printParent(fun, true) if (!args.isEmpty || needEmptyParens) inParens(printTrees(args, ", ")(given Some(cdef.symbol))) - case IsTerm(Apply(fun, args)) => + case Apply(fun, args) => printParent(fun) if (!args.isEmpty || needEmptyParens) inParens(printTrees(args, ", ")(given Some(cdef.symbol))) - case IsTerm(Select(IsNew(newTree), _)) => + case Select(newTree: New, _) => printType(newTree.tpe)(given Some(cdef.symbol)) - case IsTerm(parent) => + case parent: Term => throw new MatchError(parent.showExtractors) } @@ -211,9 +211,9 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig !flags.is(Flags.Param) && !flags.is(Flags.ParamAccessor) && !flags.is(Flags.FieldAccessor) && !isUndecompilableCaseClassMethod && !isInnerModuleObject } val stats1 = stats.collect { - case IsDefinition(stat) if keepDefinition(stat) => stat + case stat: Definition if keepDefinition(stat) => stat case stat @ Import(_, _) => stat - case IsTerm(stat) => stat + case stat: Term => stat } def printBody(printSelf: Boolean) = { @@ -245,12 +245,12 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig } this - case IsTypeDef(tdef @ TypeDef(name, rhs)) => + case tdef @ TypeDef(name, rhs) => printDefAnnotations(tdef) this += highlightKeyword("type ") printTargDef((tdef, tdef), isMember = true) - case IsValDef(vdef @ ValDef(name, tpt, rhs)) => + case vdef @ ValDef(name, tpt, rhs) => printDefAnnotations(vdef) val flags = vdef.symbol.flags @@ -287,7 +287,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig printTree(body) } - case IsDefDef(ddef @ DefDef(name, targs, argss, tpt, rhs)) => + case ddef @ DefDef(name, targs, argss, tpt, rhs) => printDefAnnotations(ddef) val isConstructor = name == "" @@ -321,7 +321,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig case Ident("_") => this += "_" - case IsIdent(tree) => + case tree: Ident => splicedName(tree.symbol) match { case Some(name) => this += name case _ => printType(tree.tpe) @@ -344,7 +344,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig } this += "this" - case IsNew(tree) => + case tree: New => this += "new " printType(tree.tpe) @@ -455,7 +455,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig case Block(stats0, expr) => val stats = stats0.filter { - case IsValDef(tree) => !tree.symbol.flags.is(Flags.Object) + case tree: ValDef => !tree.symbol.flags.is(Flags.Object) case _ => true } printFlatBlock(stats, expr) @@ -508,10 +508,10 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig this += " <: " printTypeTree(hi) - case IsWildcardTypeTree(tpt) => + case tpt: WildcardTypeTree => printTypeOrBound(tpt.tpe) - case IsTypeTree(tpt) => + case tpt: TypeTree => printTypeTree(tpt) case Closure(meth, _) => @@ -523,7 +523,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig } def printQualTree(tree: Tree): Buffer = tree match { - case IsIf(_) | IsMatch(_) | IsWhile(_) | IsTry(_) | IsReturn(_) => + case _: If | _: Match | _: While | _: Try | _: Return => this += "(" printTree(tree) this += ")" @@ -573,7 +573,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig def printFlatBlock(stats: List[Statement], expr: Term)(given elideThis: Option[Symbol]): Buffer = { val (stats1, expr1) = flatBlock(stats, expr) val stats2 = stats1.filter { - case IsTypeDef(tree) => !tree.symbol.annots.exists(_.symbol.owner.fullName == "scala.internal.Quoted$.quoteTypeTag") + case tree: TypeDef => !tree.symbol.annots.exists(_.symbol.owner.fullName == "scala.internal.Quoted$.quoteTypeTag") case _ => true } if (stats2.isEmpty) { @@ -601,7 +601,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig case _ => this += lineBreak() } next match { - case IsTerm(term) => + case term: Term => flatBlock(Nil, term) match { case (next :: _, _) => rec(next) case (Nil, next) => rec(next) @@ -748,13 +748,13 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig this += argCons.name argCons.rhs match { - case IsTypeBoundsTree(rhs) => printBoundsTree(rhs) - case IsWildcardTypeTree(rhs) => + case rhs: TypeBoundsTree => printBoundsTree(rhs) + case rhs: WildcardTypeTree => printTypeOrBound(rhs.tpe) case rhs @ LambdaTypeTree(tparams, body) => def printParam(t: Tree /*TypeTree | TypeBoundsTree*/): Unit = t match { - case IsTypeBoundsTree(t) => printBoundsTree(t) - case IsTypeTree(t) => printTypeTree(t) + case t: TypeBoundsTree => printBoundsTree(t) + case t: TypeTree => printTypeTree(t) } def printSeparated(list: List[TypeDef]): Unit = list match { case Nil => @@ -779,7 +779,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig printTypeOrBoundsTree(body) } else this - case IsTypeTree(rhs) => + case rhs: TypeTree => this += " = " printTypeTree(rhs) } @@ -830,7 +830,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig if sym.isDefDef && sym.name == "" then val ClassDef(_, _, _, _, _, body) = sym.owner.tree body.collectFirst { - case IsValDef(vdef @ ValDef(`name`, _, _)) if vdef.symbol.flags.is(Flags.ParamAccessor) => + case vdef @ ValDef(`name`, _, _) if vdef.symbol.flags.is(Flags.ParamAccessor) => if (!vdef.symbol.flags.is(Flags.Local)) { var printedPrefix = false if (vdef.symbol.flags.is(Flags.Override)) { @@ -915,7 +915,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig this += "_: " printTypeOrBoundsTree(tpt) - case IsTerm(v) => + case v: Term => printTree(v) case _ => @@ -949,9 +949,9 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig printTypeTree(lo) this += " <: " printTypeTree(hi) - case IsWildcardTypeTree(tpt) => + case tpt: WildcardTypeTree => printTypeOrBound(tpt.tpe) - case IsTypeTree(tpt) => + case tpt: TypeTree => printTypeTree(tpt) } @@ -971,13 +971,13 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig printTypeAndAnnots(tp) this += " " printAnnotation(annot) - case IsTypeRef(tpe) if tpe.typeSymbol.fullName == "scala.runtime.Null$" || tpe.typeSymbol.fullName == "scala.runtime.Nothing$" => + case tpe: TypeRef 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 IsTermRef(tpe) if tpe.termSymbol.isClassDef && tpe.termSymbol.name.endsWith("$") => + case tpe: TermRef if tpe.termSymbol.isClassDef && tpe.termSymbol.name.endsWith("$") => printType(tpe) this += ".type" - case IsTypeRef(tpe) if tpe.typeSymbol.isClassDef && tpe.typeSymbol.name.endsWith("$") => + case tpe: TypeRef if tpe.typeSymbol.isClassDef && tpe.typeSymbol.name.endsWith("$") => printType(tpe) this += ".type" case tpe @ TermRef(sym, _) => @@ -1070,7 +1070,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig case ConstantType(const) => printConstant(const) - case IsTypeRef(tpe) => + case tpe: TypeRef => val sym = tpe.typeSymbol tpe.qualifier match { case ThisType(tp) if tp.typeSymbol == defn.RootClass || tp.typeSymbol == defn.EmptyPackageClass => @@ -1081,14 +1081,14 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig if (packagePath != "") this += packagePath += "." } - case IsTermRef(prefix) if prefix.termSymbol.isClassDef => + case prefix: TermRef if prefix.termSymbol.isClassDef => printType(prefix) this += "#" - case IsTypeRef(prefix) if prefix.typeSymbol.isClassDef => + case prefix: TypeRef if prefix.typeSymbol.isClassDef => printType(prefix) this += "#" - case IsType(ThisType(TermRef(cdef, _))) if elideThis.nonEmpty && cdef == elideThis.get => - case IsType(ThisType(TypeRef(cdef, _))) if elideThis.nonEmpty && cdef == elideThis.get => + case ThisType(TermRef(cdef, _)) if elideThis.nonEmpty && cdef == elideThis.get => + case ThisType(TypeRef(cdef, _)) if elideThis.nonEmpty && cdef == elideThis.get => case IsType(prefix) => printType(prefix) this += "." @@ -1113,7 +1113,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig case AppliedType(tp, args) => tp match { - case IsTypeLambda(tp) => + case tp: TypeLambda => printType(tpe.dealias) case TypeRef(Types.ScalaPackage(), "") => this += "_*" @@ -1149,7 +1149,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig case ThisType(tp) => tp match { - case IsTypeRef(tp) if !tp.typeSymbol.flags.is(Flags.Object) => + case tp: TypeRef if !tp.typeSymbol.flags.is(Flags.Object) => printFullClassName(tp) this += highlightTypeDef(".this") case TypeRef(prefix, name) if name.endsWith("$") => @@ -1187,21 +1187,21 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig case RecursiveThis(_) => this += highlightTypeDef("this") - case IsMethodType(tpe) => + case tpe: MethodType => this += "(" printList(tpe.paramNames.zip(tpe.paramTypes), ", ", (x: (String, Type)) => (this += x._1 += ": ").printType(x._2)) this += ")" printType(tpe.resType) - case IsPolyType(tpe) => + case tpe: PolyType => this += "[" printList(tpe.paramNames.zip(tpe.paramBounds), ", ", (x: (String, TypeBounds)) => (this += x._1 += " ").printTypeOrBound(x._2)) this += "]" printType(tpe.resType) - case IsTypeLambda(tpe) => + case tpe: TypeLambda => this += "[" printList(tpe.paramNames.zip(tpe.paramBounds), ", ", (x: (String, TypeBounds)) => (this += x._1 += " ").printTypeOrBound(x._2)) @@ -1243,8 +1243,8 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig val annots = definition.symbol.annots.filter { case Annotation(annot, _) => annot.tpe match { - 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(prefix: TermRef, _) if prefix.termSymbol.fullName == "scala.annotation.internal" => false + case TypeRef(prefix: TypeRef, _) if prefix.typeSymbol.fullName == "scala.annotation.internal" => false case TypeRef(Types.ScalaPackage(), "forceInline") => false case _ => true } @@ -1276,7 +1276,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig indented { this += lineBreak() info match { - case IsTypeBounds(info) => + case info: TypeBounds => this += highlightKeyword("type ") += highlightTypeDef(name) printBounds(info) case ByNameType(_) | MethodType(_, _, _) | TypeLambda(_, _, _) => @@ -1297,7 +1297,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig def printMethodicTypeParams(paramNames: List[String], params: List[TypeOrBounds])(given elideThis: Option[Symbol]): Unit = { def printInfo(info: TypeOrBounds) = info match { - case IsTypeBounds(info) => printBounds(info) + case info: TypeBounds => printBounds(info) case IsType(info) => this += ": " printType(info) @@ -1413,7 +1413,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig private object SpecialOp { def unapply(arg: Tree)(given ctx: Context): Option[(String, List[Term])] = arg match { - case IsTerm(arg @ Apply(fn, args)) => + case arg @ Apply(fn, args) => fn.tpe match { case tpe @ TermRef(ThisType(TypeRef(_, name)), name2) if name == "" => Some((name2, args)) @@ -1437,23 +1437,23 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig object JavaLangObject { def unapply(tpe: Type)(given ctx: Context): Boolean = tpe match { - case TypeRef(IsTermRef(prefix), "Object") => prefix.typeSymbol.fullName == "java.lang" + case TypeRef(prefix: TermRef, "Object") => prefix.typeSymbol.fullName == "java.lang" case _ => false } } object Sequence { def unapply(tpe: Type)(given ctx: Context): Option[Type] = tpe match { - 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 AppliedType(TypeRef(prefix: TermRef, "Seq"), IsType(tp) :: Nil) if prefix.termSymbol.fullName == "scala.collection" => Some(tp) + case AppliedType(TypeRef(prefix: TypeRef, "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 TypeRef(IsTermRef(prefix), "Repeated") => prefix.termSymbol.fullName == "scala.annotation.internal" - case TypeRef(IsTypeRef(prefix), "Repeated") => prefix.typeSymbol.fullName == "scala.annotation.internal" + case TypeRef(prefix: TermRef, "Repeated") => prefix.termSymbol.fullName == "scala.annotation.internal" + case TypeRef(prefix: TypeRef, "Repeated") => prefix.typeSymbol.fullName == "scala.annotation.internal" case _ => false } } @@ -1467,7 +1467,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig object ScalaPackage { def unapply(tpe: TypeOrBounds)(given ctx: Context): Boolean = tpe match { - case IsTermRef(tpe) => tpe.termSymbol == defn.ScalaPackage + case tpe: TermRef => tpe.termSymbol == defn.ScalaPackage case _ => false } } diff --git a/library/src/scala/tasty/reflect/TreeOps.scala b/library/src/scala/tasty/reflect/TreeOps.scala index 62bb944e44d5..743a1b377a07 100644 --- a/library/src/scala/tasty/reflect/TreeOps.scala +++ b/library/src/scala/tasty/reflect/TreeOps.scala @@ -12,18 +12,19 @@ trait TreeOps extends Core { def symbol(given ctx: Context): Symbol = internal.Tree_symbol(self) } - object IsPackageClause { - def unapply(tree: Tree)(given ctx: Context): Option[PackageClause] = - internal.matchPackageClause(tree) - } + given (given Context): IsInstanceOf[PackageClause] = internal.isInstanceOfPackageClause + + object IsPackageClause + @deprecated("Use _: PackageClause", "") + def unapply(x: PackageClause): Some[PackageClause] = Some(x) object PackageClause { def apply(pid: Ref, stats: List[Tree])(given ctx: Context): PackageClause = internal.PackageClause_apply(pid, stats) def copy(original: Tree)(pid: Ref, stats: List[Tree])(given ctx: Context): PackageClause = internal.PackageClause_copy(original)(pid, stats) - def unapply(tree: Tree)(given ctx: Context): Option[(Ref, List[Tree])] = - internal.matchPackageClause(tree).map(x => (x.pid, x.stats)) + def unapply(tree: PackageClause)(given ctx: Context): Some[(Ref, List[Tree])] = + Some((tree.pid, tree.stats)) } given PackageClauseOps: (self: PackageClause) { @@ -31,18 +32,19 @@ trait TreeOps extends Core { def stats(given ctx: Context): List[Tree] = internal.PackageClause_stats(self) } - object IsImport { - def unapply(tree: Tree)(given ctx: Context): Option[Import] = - internal.matchImport(tree) - } + given (given Context): IsInstanceOf[Import] = internal.isInstanceOfImport + + object IsImport + @deprecated("Use _: Import", "") + def unapply(x: Import): Some[Import] = Some(x) object Import { def apply(expr: Term, selectors: List[ImportSelector])(given ctx: Context): Import = internal.Import_apply(expr, selectors) def copy(original: Tree)(expr: Term, selectors: List[ImportSelector])(given ctx: Context): Import = internal.Import_copy(original)(expr, selectors) - def unapply(tree: Tree)(given ctx: Context): Option[(Term, List[ImportSelector])] = - internal.matchImport(tree).map(x => (x.expr, x.selectors)) + def unapply(tree: Import)(given ctx: Context): Option[(Term, List[ImportSelector])] = + Some((tree.expr, tree.selectors)) } given ImportOps: (self: Import) { @@ -51,16 +53,19 @@ trait TreeOps extends Core { internal.Import_selectors(self) } - object IsStatement { - /** Matches any Statement and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Statement] = internal.matchStatement(tree) - } + given (given Context): IsInstanceOf[Statement] = internal.isInstanceOfStatement + + object IsStatement + @deprecated("Use _: Statement", "") + def unapply(x: Statement): Option[Statement] = Some(x) // ----- Definitions ---------------------------------------------- - object IsDefinition { - def unapply(tree: Tree)(given ctx: Context): Option[Definition] = internal.matchDefinition(tree) - } + given (given Context): IsInstanceOf[Definition] = internal.isInstanceOfDefinition + + object IsDefinition + @deprecated("Use _: Definition", "") + def unapply(x: Definition): Option[Definition] = Some(x) given DefinitionOps: (self: Definition) { def name(given ctx: Context): String = internal.Definition_name(self) @@ -68,16 +73,18 @@ trait TreeOps extends Core { // ClassDef - object IsClassDef { - def unapply(tree: Tree)(given ctx: Context): Option[ClassDef] = internal.matchClassDef(tree) - } + given (given Context): IsInstanceOf[ClassDef] = internal.isInstanceOfClassDef + + object IsClassDef + @deprecated("Use _: ClassDef", "") + def unapply(x: ClassDef): Some[ClassDef] = Some(x) object ClassDef { // TODO def apply(name: String, constr: DefDef, parents: List[TermOrTypeTree], selfOpt: Option[ValDef], body: List[Statement])(given ctx: Context): ClassDef def copy(original: Tree)(name: String, constr: DefDef, parents: List[Tree /* Term | TypeTree */], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement])(given ctx: Context): ClassDef = internal.ClassDef_copy(original)(name, constr, parents, derived, selfOpt, body) - def unapply(tree: Tree)(given ctx: Context): Option[(String, DefDef, List[Tree /* Term | TypeTree */], List[TypeTree], Option[ValDef], List[Statement])] = - internal.matchClassDef(tree).map(x => (x.name, x.constructor, x.parents, x.derived, x.self, x.body)) + def unapply(cdef: ClassDef)(given ctx: Context): Option[(String, DefDef, List[Tree /* Term | TypeTree */], List[TypeTree], Option[ValDef], List[Statement])] = + Some((cdef.name, cdef.constructor, cdef.parents, cdef.derived, cdef.self, cdef.body)) } given ClassDefOps: (self: ClassDef) { @@ -90,17 +97,19 @@ trait TreeOps extends Core { // DefDef - object IsDefDef { - def unapply(tree: Tree)(given ctx: Context): Option[DefDef] = internal.matchDefDef(tree) - } + given (given Context): IsInstanceOf[DefDef] = internal.isInstanceOfDefDef + + object IsDefDef + @deprecated("Use _: DefDef", "") + def unapply(x: DefDef): Some[DefDef] = Some(x) object DefDef { def apply(symbol: Symbol, rhsFn: List[Type] => List[List[Term]] => Option[Term])(given ctx: Context): DefDef = internal.DefDef_apply(symbol, rhsFn) def copy(original: Tree)(name: String, typeParams: List[TypeDef], paramss: List[List[ValDef]], tpt: TypeTree, rhs: Option[Term])(given ctx: Context): DefDef = internal.DefDef_copy(original)(name, typeParams, paramss, tpt, rhs) - def unapply(tree: Tree)(given ctx: Context): Option[(String, List[TypeDef], List[List[ValDef]], TypeTree, Option[Term])] = - internal.matchDefDef(tree).map(x => (x.name, x.typeParams, x.paramss, x.returnTpt, x.rhs)) + def unapply(ddef: DefDef)(given ctx: Context): Option[(String, List[TypeDef], List[List[ValDef]], TypeTree, Option[Term])] = + Some((ddef.name, ddef.typeParams, ddef.paramss, ddef.returnTpt, ddef.rhs)) } given DefDefOps: (self: DefDef) { @@ -112,17 +121,19 @@ trait TreeOps extends Core { // ValDef - object IsValDef { - def unapply(tree: Tree)(given ctx: Context): Option[ValDef] = internal.matchValDef(tree) - } + given (given Context): IsInstanceOf[ValDef] = internal.isInstanceOfValDef + + object IsValDef + @deprecated("Use _: ValDef", "") + def unapply(x: ValDef): Some[ValDef] = Some(x) object ValDef { def apply(symbol: Symbol, rhs: Option[Term])(given ctx: Context): ValDef = internal.ValDef_apply(symbol, rhs) def copy(original: Tree)(name: String, tpt: TypeTree, rhs: Option[Term])(given ctx: Context): ValDef = internal.ValDef_copy(original)(name, tpt, rhs) - def unapply(tree: Tree)(given ctx: Context): Option[(String, TypeTree, Option[Term])] = - internal.matchValDef(tree).map(x => (x.name, x.tpt, x.rhs)) + def unapply(vdef: ValDef)(given ctx: Context): Option[(String, TypeTree, Option[Term])] = + Some((vdef.name, vdef.tpt, vdef.rhs)) } given ValDefOps: (self: ValDef) { @@ -132,17 +143,19 @@ trait TreeOps extends Core { // TypeDef - object IsTypeDef { - def unapply(tree: Tree)(given ctx: Context): Option[TypeDef] = internal.matchTypeDef(tree) - } + given (given Context): IsInstanceOf[TypeDef] = internal.isInstanceOfTypeDef + + object IsTypeDef + @deprecated("Use _: TypeDef", "") + def unapply(x: TypeDef): Some[TypeDef] = Some(x) object TypeDef { def apply(symbol: Symbol)(given ctx: Context): TypeDef = internal.TypeDef_apply(symbol) def copy(original: Tree)(name: String, rhs: Tree /*TypeTree | TypeBoundsTree*/)(given ctx: Context): TypeDef = internal.TypeDef_copy(original)(name, rhs) - def unapply(tree: Tree)(given ctx: Context): Option[(String, Tree /*TypeTree | TypeBoundsTree*/ /* TypeTree | TypeBoundsTree */)] = - internal.matchTypeDef(tree).map(x => (x.name, x.rhs)) + def unapply(tdef: TypeDef)(given ctx: Context): Option[(String, Tree /*TypeTree | TypeBoundsTree*/ /* TypeTree | TypeBoundsTree */)] = + Some((tdef.name, tdef.rhs)) } given TypeDefOps: (self: TypeDef) { @@ -151,19 +164,20 @@ trait TreeOps extends Core { // PackageDef - object IsPackageDef { - def unapply(tree: Tree)(given ctx: Context): Option[PackageDef] = - internal.matchPackageDef(tree) - } + given (given Context): IsInstanceOf[PackageDef] = internal.isInstanceOfPackageDef given PackageDefOps: (self: PackageDef) { def owner(given ctx: Context): PackageDef = internal.PackageDef_owner(self) def members(given ctx: Context): List[Statement] = internal.PackageDef_members(self) } + object IsPackageDef + @deprecated("Use _: PackageDef", "") + def unapply(x: PackageDef): Some[PackageDef] = Some(x) + object PackageDef { - def unapply(tree: Tree)(given ctx: Context): Option[(String, PackageDef)] = - internal.matchPackageDef(tree).map(x => (x.name, x.owner)) + def unapply(tree: PackageDef)(given ctx: Context): Option[(String, PackageDef)] = + Some((tree.name, tree.owner)) } // ----- Terms ---------------------------------------------------- @@ -213,16 +227,17 @@ trait TreeOps extends Core { def select(sym: Symbol)(given ctx: Context): Select = Select(self, sym) } - object IsTerm { - /** Matches any term */ - def unapply(tree: Tree)(given ctx: Context): Option[Term] = - internal.matchTerm(tree) - } + given (given Context): IsInstanceOf[Term] = internal.isInstanceOfTerm - object IsRef { - /** Matches any Ref and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Ref] = internal.matchRef(tree) - } + object IsTerm + @deprecated("Use _: Term", "") + def unapply(x: Term): Some[Term] = Some(x) + + given (given Context): IsInstanceOf[Ref] = internal.isInstanceOfRef + + object IsRef + @deprecated("Use _: Ref", "") + def unapply(x: Ref): Some[Ref] = Some(x) object Ref { @@ -234,16 +249,17 @@ trait TreeOps extends Core { } - object IsIdent { - /** Matches any Ident and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Ident] = internal.matchIdent(tree) - } + given (given Context): IsInstanceOf[Ident] = internal.isInstanceOfIdent given IdentOps: (self: Ident) { def name(given ctx: Context): String = internal.Ident_name(self) } /** Scala term identifier */ + object IsIdent + @deprecated("Use _: Ident", "") + def unapply(x: Ident): Some[Ident] = Some(x) + object Ident { def apply(tmref: TermRef)(given ctx: Context): Term = internal.Ident_apply(tmref) @@ -252,16 +268,17 @@ trait TreeOps extends Core { internal.Ident_copy(original)(name) /** Matches a term identifier and returns its name */ - def unapply(tree: Tree)(given ctx: Context): Option[String] = - internal.matchIdent(tree).map(_.name) + def unapply(tree: Ident)(given ctx: Context): Option[String] = + Some(tree.name) } - object IsSelect { - /** Matches any Select and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Select] = internal.matchSelect(tree) - } + given (given Context): IsInstanceOf[Select] = internal.isInstanceOfSelect /** Scala term selection */ + object IsSelect + @deprecated("Use _: Select", "") + def unapply(x: Select): Some[Select] = Some(x) + object Select { /** Select a term member by symbol */ def apply(qualifier: Term, symbol: Symbol)(given ctx: Context): Select = @@ -285,8 +302,8 @@ trait TreeOps extends Core { internal.Select_copy(original)(qualifier, name) /** Matches `.` */ - def unapply(tree: Tree)(given ctx: Context): Option[(Term, String)] = - internal.matchSelect(tree).map(x => (x.qualifier, x.name)) + def unapply(x: Select)(given ctx: Context): Option[(Term, String)] = + Some((x.qualifier, x.name)) } given SelectOps: (self: Select) { @@ -295,12 +312,14 @@ trait TreeOps extends Core { def signature(given ctx: Context): Option[Signature] = internal.Select_signature(self) } - object IsLiteral { - /** Matches any Literal and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Literal] = internal.matchLiteral(tree) - } + given (given Context): IsInstanceOf[Literal] = + internal.isInstanceOfLiteral /** Scala literal constant */ + object IsLiteral + @deprecated("Use _: Literal", "") + def unapply(x: Literal): Some[Literal] = Some(x) + object Literal { /** Create a literal constant */ @@ -311,20 +330,21 @@ trait TreeOps extends Core { internal.Literal_copy(original)(constant) /** Matches a literal constant */ - def unapply(tree: Tree)(given ctx: Context): Option[Constant] = - internal.matchLiteral(tree).map(_.constant) + def unapply(x: Literal)(given ctx: Context): Option[Constant] = + Some(x.constant) } given LiteralOps: (self: Literal) { def constant(given ctx: Context): Constant = internal.Literal_constant(self) } - object IsThis { - /** Matches any This and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[This] = internal.matchThis(tree) - } + given (given Context): IsInstanceOf[This] = internal.isInstanceOfThis /** Scala `this` or `this[id]` */ + object IsThis + @deprecated("Use _: This", "") + def unapply(x: This): Some[This] = Some(x) + object This { /** Create a `this[` */ @@ -335,8 +355,7 @@ trait TreeOps extends Core { internal.This_copy(original)(qual) /** Matches `this[` */ - def unapply(tree: Tree)(given ctx: Context): Option[Option[Id]] = - internal.matchThis(tree).map(_.id) + def unapply(x: This)(given ctx: Context): Option[Option[Id]] = Some(x.id) } @@ -344,12 +363,13 @@ trait TreeOps extends Core { def id(given ctx: Context): Option[Id] = internal.This_id(self) } - object IsNew { - /** Matches any New and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[New] = internal.matchNew(tree) - } + given (given Context): IsInstanceOf[New] = internal.isInstanceOfNew /** Scala `new` */ + object IsNew + @deprecated("Use _: New", "") + def unapply(x: New): Some[New] = Some(x) + object New { /** Create a `new ` */ @@ -360,20 +380,20 @@ trait TreeOps extends Core { internal.New_copy(original)(tpt) /** Matches a `new ` */ - def unapply(tree: Tree)(given ctx: Context): Option[TypeTree] = - internal.matchNew(tree).map(_.tpt) + def unapply(x: New)(given ctx: Context): Option[TypeTree] = Some(x.tpt) } given NewOps: (self: New) { def tpt(given ctx: Context): TypeTree = internal.New_tpt(self) } - object IsNamedArg { - /** Matches any NamedArg and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[NamedArg] = internal.matchNamedArg(tree) - } + given (given Context): IsInstanceOf[NamedArg] = internal.isInstanceOfNamedArg /** Scala named argument `x = y` in argument position */ + object IsNamedArg + @deprecated("Use _: NamedArg", "") + def unapply(x: NamedArg): Some[NamedArg] = Some(x) + object NamedArg { /** Create a named argument ` = ` */ @@ -384,8 +404,8 @@ trait TreeOps extends Core { internal.NamedArg_copy(original)(name, arg) /** Matches a named argument ` = ` */ - def unapply(tree: Tree)(given ctx: Context): Option[(String, Term)] = - internal.matchNamedArg(tree).map(x => (x.name, x.value)) + def unapply(x: NamedArg)(given ctx: Context): Option[(String, Term)] = + Some((x.name, x.value)) } @@ -394,12 +414,13 @@ trait TreeOps extends Core { def value(given ctx: Context): Term = internal.NamedArg_value(self) } - object IsApply { - /** Matches any Apply and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Apply] = internal.matchApply(tree) - } + given (given Context): IsInstanceOf[Apply] = internal.isInstanceOfApply /** Scala parameter application */ + object IsApply + @deprecated("Use _: Apply", "") + def unapply(x: Apply): Some[Apply] = Some(x) + object Apply { /** Create a function application `()` */ @@ -410,8 +431,8 @@ trait TreeOps extends Core { internal.Apply_copy(original)(fun, args) /** Matches a function application `()` */ - def unapply(tree: Tree)(given ctx: Context): Option[(Term, List[Term])] = - internal.matchApply(tree).map(x => (x.fun, x.args)) + def unapply(x: Apply)(given ctx: Context): Option[(Term, List[Term])] = + Some((x.fun, x.args)) } given ApplyOps: (self: Apply) { @@ -419,13 +440,13 @@ trait TreeOps extends Core { def args(given ctx: Context): List[Term] = internal.Apply_args(self) } - object IsTypeApply { - /** Matches any TypeApply and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[TypeApply] = - internal.matchTypeApply(tree) - } + given (given Context): IsInstanceOf[TypeApply] = internal.isInstanceOfTypeApply /** Scala type parameter application */ + object IsTypeApply + @deprecated("Use _: TypeApply", "") + def unapply(x: TypeApply): Some[TypeApply] = Some(x) + object TypeApply { /** Create a function type application `[]` */ @@ -436,8 +457,8 @@ trait TreeOps extends Core { internal.TypeApply_copy(original)(fun, args) /** Matches a function type application `[]` */ - def unapply(tree: Tree)(given ctx: Context): Option[(Term, List[TypeTree])] = - internal.matchTypeApply(tree).map(x => (x.fun, x.args)) + def unapply(x: TypeApply)(given ctx: Context): Option[(Term, List[TypeTree])] = + Some((x.fun, x.args)) } @@ -446,12 +467,13 @@ trait TreeOps extends Core { def args(given ctx: Context): List[TypeTree] = internal.TypeApply_args(self) } - object IsSuper { - /** Matches any Super and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Super] = internal.matchSuper(tree) - } + given (given Context): IsInstanceOf[Super] = internal.isInstanceOfSuper /** Scala `x.super` or `x.super[id]` */ + object IsSuper + @deprecated("Use _: Super", "") + def unapply(x: Super): Some[Super] = Some(x) + object Super { /** Creates a `.super[` */ @@ -462,8 +484,8 @@ trait TreeOps extends Core { internal.Super_copy(original)(qual, mix) /** Matches a `.super[` */ - def unapply(tree: Tree)(given ctx: Context): Option[(Term, Option[Id])] = - internal.matchSuper(tree).map(x => (x.qualifier, x.id)) + def unapply(x: Super)(given ctx: Context): Option[(Term, Option[Id])] = + Some((x.qualifier, x.id)) } given SuperOps: (self: Super) { @@ -471,12 +493,13 @@ trait TreeOps extends Core { def id(given ctx: Context): Option[Id] = internal.Super_id(self) } - object IsTyped { - /** Matches any Typed and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Typed] = internal.matchTyped(tree) - } + given (given Context): IsInstanceOf[Typed] = internal.isInstanceOfTyped /** Scala ascription `x: T` */ + object IsTyped + @deprecated("Use _: Typed", "") + def unapply(x: Typed): Some[Typed] = Some(x) + object Typed { /** Create a type ascription `: ` */ @@ -487,8 +510,8 @@ trait TreeOps extends Core { internal.Typed_copy(original)(expr, tpt) /** Matches `: ` */ - def unapply(tree: Tree)(given ctx: Context): Option[(Term, TypeTree)] = - internal.matchTyped(tree).map(x => (x.expr, x.tpt)) + def unapply(x: Typed)(given ctx: Context): Option[(Term, TypeTree)] = + Some((x.expr, x.tpt)) } @@ -497,12 +520,13 @@ trait TreeOps extends Core { def tpt(given ctx: Context): TypeTree = internal.Typed_tpt(self) } - object IsAssign { - /** Matches any Assign and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Assign] = internal.matchAssign(tree) - } + given (given Context): IsInstanceOf[Assign] = internal.isInstanceOfAssign /** Scala assign `x = y` */ + object IsAssign + @deprecated("Use _: Assign", "") + def unapply(x: Assign): Some[Assign] = Some(x) + object Assign { /** Create an assignment ` = ` */ @@ -513,8 +537,8 @@ trait TreeOps extends Core { internal.Assign_copy(original)(lhs, rhs) /** Matches an assignment ` = ` */ - def unapply(tree: Tree)(given ctx: Context): Option[(Term, Term)] = - internal.matchAssign(tree).map(x => (x.lhs, x.rhs)) + def unapply(x: Assign)(given ctx: Context): Option[(Term, Term)] = + Some((x.lhs, x.rhs)) } given AssignOps: (self: Assign) { @@ -522,12 +546,13 @@ trait TreeOps extends Core { def rhs(given ctx: Context): Term = internal.Assign_rhs(self) } - object IsBlock { - /** Matches any Block and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Block] = internal.matchBlock(tree) - } + given (given Context): IsInstanceOf[Block] = internal.isInstanceOfBlock /** Scala code block `{ stat0; ...; statN; expr }` term */ + object IsBlock + @deprecated("Use _: Block", "") + def unapply(x: Block): Some[Block] = Some(x) + object Block { /** Creates a block `{ ; }` */ @@ -538,8 +563,8 @@ trait TreeOps extends Core { internal.Block_copy(original)(stats, expr) /** Matches a block `{ ; }` */ - def unapply(tree: Tree)(given ctx: Context): Option[(List[Statement], Term)] = - internal.matchBlock(tree).map(x => (x.statements, x.expr)) + def unapply(x: Block)(given ctx: Context): Option[(List[Statement], Term)] = + Some((x.statements, x.expr)) } given BlockOps: (self: Block) { @@ -547,10 +572,11 @@ trait TreeOps extends Core { def expr(given ctx: Context): Term = internal.Block_expr(self) } - object IsClosure { - /** Matches any Closure and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Closure] = internal.matchClosure(tree) - } + given (given Context): IsInstanceOf[Closure] = internal.isInstanceOfClosure + + object IsClosure + @deprecated("Use _: Closure", "") + def unapply(x: Closure): Some[Closure] = Some(x) object Closure { @@ -560,8 +586,8 @@ trait TreeOps extends Core { def copy(original: Tree)(meth: Tree, tpt: Option[Type])(given ctx: Context): Closure = internal.Closure_copy(original)(meth, tpt) - def unapply(tree: Tree)(given ctx: Context): Option[(Term, Option[Type])] = - internal.matchClosure(tree).map(x => (x.meth, x.tpeOpt)) + def unapply(x: Closure)(given ctx: Context): Option[(Term, Option[Type])] = + Some((x.meth, x.tpeOpt)) } given ClosureOps: (self: Closure) { @@ -591,10 +617,11 @@ trait TreeOps extends Core { } } - object IsIf { - /** Matches any If and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[If] = internal.matchIf(tree) - } + given (given Context): IsInstanceOf[If] = internal.isInstanceOfIf + + object IsIf + @deprecated("Use _: If", "") + def unapply(x: If): Some[If] = Some(x) /** Scala `if`/`else` term */ object If { @@ -607,8 +634,8 @@ trait TreeOps extends Core { internal.If_copy(original)(cond, thenp, elsep) /** Matches an if/then/else `if () else ` */ - def unapply(tree: Tree)(given ctx: Context): Option[(Term, Term, Term)] = - internal.matchIf(tree).map(x => (x.cond, x.thenp, x.elsep)) + def unapply(tree: If)(given ctx: Context): Option[(Term, Term, Term)] = + Some((tree.cond, tree.thenp, tree.elsep)) } @@ -618,12 +645,13 @@ trait TreeOps extends Core { def elsep(given ctx: Context): Term = internal.If_elsep(self) } - object IsMatch { - /** Matches any Match and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Match] = internal.matchMatch(tree) - } + given (given Context): IsInstanceOf[Match] = internal.isInstanceOfMatch /** Scala `match` term */ + object IsMatch + @deprecated("Use _: Match", "") + def unapply(x: Match): Some[Match] = Some(x) + object Match { /** Creates a pattern match ` match { }` */ @@ -634,8 +662,8 @@ trait TreeOps extends Core { internal.Match_copy(original)(selector, cases) /** Matches a pattern match ` match { }` */ - def unapply(tree: Tree)(given ctx: Context): Option[(Term, List[CaseDef])] = - internal.matchMatch(tree).map(x => (x.scrutinee, x.cases)) + def unapply(x: Match)(given ctx: Context): Option[(Term, List[CaseDef])] = + Some((x.scrutinee, x.cases)) } @@ -644,12 +672,13 @@ trait TreeOps extends Core { def cases(given ctx: Context): List[CaseDef] = internal.Match_cases(self) } - object IsImplicitMatch { - /** Matches any ImpliedMatch and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[ImpliedMatch] = internal.matchImplicitMatch(tree) - } + given (given Context): IsInstanceOf[ImpliedMatch] = internal.isInstanceOfImpliedMatch /** Scala implicit `match` term */ + object IsImpliedMatch + @deprecated("Use _: ImpliedMatch", "") + def unapply(x: ImpliedMatch): Some[ImpliedMatch] = Some(x) + object ImpliedMatch { /** Creates a pattern match `delegate match { }` */ @@ -660,8 +689,7 @@ trait TreeOps extends Core { internal.ImplicitMatch_copy(original)(cases) /** Matches a pattern match `delegate match { }` */ - def unapply(tree: Tree)(given ctx: Context): Option[List[CaseDef]] = - internal.matchImplicitMatch(tree).map(_.cases) + def unapply(x: ImpliedMatch)(given ctx: Context): Option[List[CaseDef]] = Some(x.cases) } @@ -669,12 +697,13 @@ trait TreeOps extends Core { def cases(given ctx: Context): List[CaseDef] = internal.ImplicitMatch_cases(self) } - object IsTry { - /** Matches any Try and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Try] = internal.matchTry(tree) - } + given (given Context): IsInstanceOf[Try] = internal.isInstanceOfTry /** Scala `try`/`catch`/`finally` term */ + object IsTry + @deprecated("Use _: Try", "") + def unapply(x: Try): Some[Try] = Some(x) + object Try { /** Create a try/catch `try catch { } finally ` */ @@ -685,8 +714,8 @@ trait TreeOps extends Core { internal.Try_copy(original)(expr, cases, finalizer) /** Matches a try/catch `try catch { } finally ` */ - def unapply(tree: Tree)(given ctx: Context): Option[(Term, List[CaseDef], Option[Term])] = - internal.matchTry(tree).map(x => (x.body, x.cases, x.finalizer)) + def unapply(x: Try)(given ctx: Context): Option[(Term, List[CaseDef], Option[Term])] = + Some((x.body, x.cases, x.finalizer)) } @@ -696,12 +725,13 @@ trait TreeOps extends Core { def finalizer(given ctx: Context): Option[Term] = internal.Try_finalizer(self) } - object IsReturn { - /** Matches any Return and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Return] = internal.matchReturn(tree) - } + given (given Context): IsInstanceOf[Return] = internal.isInstanceOfReturn /** Scala local `return` */ + object IsReturn + @deprecated("Use _: Return", "") + def unapply(x: Return): Some[Return] = Some(x) + object Return { /** Creates `return ` */ @@ -712,8 +742,7 @@ trait TreeOps extends Core { internal.Return_copy(original)(expr) /** Matches `return ` */ - def unapply(tree: Tree)(given ctx: Context): Option[Term] = - internal.matchReturn(tree).map(_.expr) + def unapply(x: Return)(given ctx: Context): Option[Term] = Some(x.expr) } @@ -721,10 +750,11 @@ trait TreeOps extends Core { def expr(given ctx: Context): Term = internal.Return_expr(self) } - object IsRepeated { - /** Matches any Repeated and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Repeated] = internal.matchRepeated(tree) - } + given (given Context): IsInstanceOf[Repeated] = internal.isInstanceOfRepeated + + object IsRepeated + @deprecated("Use _: Repeated", "") + def unapply(x: Repeated): Some[Repeated] = Some(x) object Repeated { @@ -734,8 +764,8 @@ trait TreeOps extends Core { def copy(original: Tree)(elems: List[Term], tpt: TypeTree)(given ctx: Context): Repeated = internal.Repeated_copy(original)(elems, tpt) - def unapply(tree: Tree)(given ctx: Context): Option[(List[Term], TypeTree)] = - internal.matchRepeated(tree).map(x => (x.elems, x.elemtpt)) + def unapply(x: Repeated)(given ctx: Context): Option[(List[Term], TypeTree)] = + Some((x.elems, x.elemtpt)) } @@ -744,10 +774,11 @@ trait TreeOps extends Core { def elemtpt(given ctx: Context): TypeTree = internal.Repeated_elemtpt(self) } - object IsInlined { - /** Matches any Inlined and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Inlined] = internal.matchInlined(tree) - } + given (given Context): IsInstanceOf[Inlined] = internal.isInstanceOfInlined + + object IsInlined + @deprecated("Use _: Inlined", "") + def unapply(x: Inlined): Some[Inlined] = Some(x) object Inlined { @@ -757,8 +788,8 @@ trait TreeOps extends Core { def copy(original: Tree)(call: Option[Tree /* Term | TypeTree */], bindings: List[Definition], expansion: Term)(given ctx: Context): Inlined = internal.Inlined_copy(original)(call, bindings, expansion) - def unapply(tree: Tree)(given ctx: Context): Option[(Option[Tree /* Term | TypeTree */], List[Definition], Term)] = - internal.matchInlined(tree).map(x => (x.call, x.bindings, x.body)) + def unapply(x: Inlined)(given ctx: Context): Option[(Option[Tree /* Term | TypeTree */], List[Definition], Term)] = + Some((x.call, x.bindings, x.body)) } @@ -768,10 +799,11 @@ trait TreeOps extends Core { def body(given ctx: Context): Term = internal.Inlined_body(self) } - object IsSelectOuter { - /** Matches any SelectOuter and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[SelectOuter] = internal.matchSelectOuter(tree) - } + given (given Context): IsInstanceOf[SelectOuter] = internal.isInstanceOfSelectOuter + + object IsSelectOuter + @deprecated("Use _: SelectOuter", "") + def unapply(x: SelectOuter): Some[SelectOuter] = Some(x) object SelectOuter { @@ -781,8 +813,8 @@ trait TreeOps extends Core { def copy(original: Tree)(qualifier: Term, name: String, levels: Int)(given ctx: Context): SelectOuter = internal.SelectOuter_copy(original)(qualifier, name, levels) - def unapply(tree: Tree)(given ctx: Context): Option[(Term, Int, Type)] = // TODO homogenize order of parameters - internal.matchSelectOuter(tree).map(x => (x.qualifier, x.level, x.tpe)) + def unapply(x: SelectOuter)(given ctx: Context): Option[(Term, Int, Type)] = // TODO homogenize order of parameters + Some((x.qualifier, x.level, x.tpe)) } @@ -791,10 +823,11 @@ trait TreeOps extends Core { def level(given ctx: Context): Int = internal.SelectOuter_level(self) } - object IsWhile { - /** Matches any While and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[While] = internal.matchWhile(tree) - } + given (given Context): IsInstanceOf[While] = internal.isInstanceOfWhile + + object IsWhile + @deprecated("Use _: While", "") + def unapply(x: While): Some[While] = Some(x) object While { @@ -806,8 +839,8 @@ trait TreeOps extends Core { internal.While_copy(original)(cond, body) /** Extractor for while loops. Matches `while () ` and returns (, ) */ - def unapply(tree: Tree)(given ctx: Context): Option[(Term, Term)] = - internal.matchWhile(tree).map(x => (x.cond, x.body)) + def unapply(x: While)(given ctx: Context): Option[(Term, Term)] = + Some((x.cond, x.body)) } @@ -823,57 +856,57 @@ trait TreeOps extends Core { def tpe(given ctx: Context): Type = internal.TypeTree_tpe(self) } - object IsTypeTree { - def unapply(tpt: Tree)(given ctx: Context): Option[TypeTree] = - internal.matchTypeTree(tpt) - } + given (given Context): IsInstanceOf[TypeTree] = + internal.isInstanceOfTypeTree - object IsInferred { - /** Matches any Inferred and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Inferred] = - internal.matchInferred(tree) - } + object IsTypeTree + @deprecated("Use _: TypeTree", "") + def unapply(x: TypeTree): Option[TypeTree] = Some(x) + + given (given Context): IsInstanceOf[Inferred] = internal.isInstanceOfInferred /** TypeTree containing an inferred type */ + object IsInferred + @deprecated("Use _: Inferred", "") + def unapply(x: Inferred): Some[Inferred] = Some(x) + object Inferred { def apply(tpe: Type)(given ctx: Context): Inferred = internal.Inferred_apply(tpe) /** Matches a TypeTree containing an inferred type */ - def unapply(tree: Tree)(given ctx: Context): Boolean = - internal.matchInferred(tree).isDefined + def unapply(x: Inferred)(given ctx: Context): Boolean = true } - object IsTypeIdent { - /** Matches any TypeIdent and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[TypeIdent] = - internal.matchTypeIdent(tree) - } + given (given Context): IsInstanceOf[TypeIdent] = internal.isInstanceOfTypeIdent given TypeIdentOps: (self: TypeIdent) { def name(given ctx: Context): String = internal.TypeIdent_name(self) } + object IsTypeIdent + @deprecated("Use _: TypeIdent", "") + def unapply(x: TypeIdent): Some[TypeIdent] = Some(x) + object TypeIdent { // TODO def apply(name: String)(given ctx: Context): TypeIdent def copy(original: Tree)(name: String)(given ctx: Context): TypeIdent = internal.TypeIdent_copy(original)(name) - def unapply(tree: Tree)(given ctx: Context): Option[String] = - internal.matchTypeIdent(tree).map(_.name) + def unapply(x: TypeIdent)(given ctx: Context): Option[String] = Some(x.name) } - object IsTypeSelect { - /** Matches any TypeSelect and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[TypeSelect] = - internal.matchTypeSelect(tree) - } + given (given Context): IsInstanceOf[TypeSelect] = internal.isInstanceOfTypeSelect + + object IsTypeSelect + @deprecated("Use _: TypeSelect", "") + def unapply(x: TypeSelect): Some[TypeSelect] = Some(x) object TypeSelect { def apply(qualifier: Term, name: String)(given ctx: Context): TypeSelect = internal.TypeSelect_apply(qualifier, name) def copy(original: Tree)(qualifier: Term, name: String)(given ctx: Context): TypeSelect = internal.TypeSelect_copy(original)(qualifier, name) - def unapply(tree: Tree)(given ctx: Context): Option[(Term, String)] = - internal.matchTypeSelect(tree).map(x => (x.qualifier, x.name)) + def unapply(x: TypeSelect)(given ctx: Context): Option[(Term, String)] = + Some((x.qualifier, x.name)) } given TypeSelectOps: (self: TypeSelect) { @@ -881,18 +914,18 @@ trait TreeOps extends Core { def name(given ctx: Context): String = internal.TypeSelect_name(self) } - object IsProjection { - /** Matches any Projection and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Projection] = - internal.matchProjection(tree) - } + given (given Context): IsInstanceOf[Projection] = internal.isInstanceOfProjection + + object IsProjection + @deprecated("Use _: Projection", "") + def unapply(x: Projection): Some[Projection] = Some(x) object Projection { // TODO def apply(qualifier: TypeTree, name: String)(given ctx: Context): Project def copy(original: Tree)(qualifier: TypeTree, name: String)(given ctx: Context): Projection = internal.Projection_copy(original)(qualifier, name) - def unapply(tree: Tree)(given ctx: Context): Option[(TypeTree, String)] = - internal.matchProjection(tree).map(x => (x.qualifier, x.name)) + def unapply(x: Projection)(given ctx: Context): Option[(TypeTree, String)] = + Some((x.qualifier, x.name)) } given ProjectionOps: (self: Projection) { @@ -900,37 +933,38 @@ trait TreeOps extends Core { def name(given ctx: Context): String = internal.Projection_name(self) } - object IsSingleton { - /** Matches any Singleton and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Singleton] = - internal.matchSingleton(tree) - } + given (given Context): IsInstanceOf[Singleton] = + internal.isInstanceOfSingleton + + object IsSingleton + @deprecated("Use _: Singleton", "") + def unapply(x: Singleton): Some[Singleton] = Some(x) object Singleton { def apply(ref: Term)(given ctx: Context): Singleton = internal.Singleton_apply(ref) def copy(original: Tree)(ref: Term)(given ctx: Context): Singleton = internal.Singleton_copy(original)(ref) - def unapply(tree: Tree)(given ctx: Context): Option[Term] = - internal.matchSingleton(tree).map(_.ref) + def unapply(x: Singleton)(given ctx: Context): Option[Term] = + Some(x.ref) } given SingletonOps: (self: Singleton) { def ref(given ctx: Context): Term = internal.Singleton_ref(self) } - object IsRefined { - /** Matches any Refined and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Refined] = - internal.matchRefined(tree) - } + given (given Context): IsInstanceOf[Refined] = internal.isInstanceOfRefined + + object IsRefined + @deprecated("Use _: Refined", "") + def unapply(x: Refined): Some[Refined] = Some(x) object Refined { // TODO def apply(tpt: TypeTree, refinements: List[Definition])(given ctx: Context): Refined def copy(original: Tree)(tpt: TypeTree, refinements: List[Definition])(given ctx: Context): Refined = internal.Refined_copy(original)(tpt, refinements) - def unapply(tree: Tree)(given ctx: Context): Option[(TypeTree, List[Definition])] = - internal.matchRefined(tree).map(x => (x.tpt, x.refinements)) + def unapply(x: Refined)(given ctx: Context): Option[(TypeTree, List[Definition])] = + Some((x.tpt, x.refinements)) } given RefinedOps: (self: Refined) { @@ -938,19 +972,19 @@ trait TreeOps extends Core { def refinements(given ctx: Context): List[Definition] = internal.Refined_refinements(self) } - object IsApplied { - /** Matches any Applied and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Applied] = - internal.matchApplied(tree) - } + given (given Context): IsInstanceOf[Applied] = internal.isInstanceOfApplied + + object IsApplied + @deprecated("Use _: Applied", "") + def unapply(x: Applied): Some[Applied] = Some(x) object Applied { def apply(tpt: TypeTree, args: List[Tree /*TypeTree | TypeBoundsTree*/])(given ctx: Context): Applied = internal.Applied_apply(tpt, args) def copy(original: Tree)(tpt: TypeTree, args: List[Tree /*TypeTree | TypeBoundsTree*/])(given ctx: Context): Applied = internal.Applied_copy(original)(tpt, args) - def unapply(tree: Tree)(given ctx: Context): Option[(TypeTree, List[Tree /*TypeTree | TypeBoundsTree*/])] = - internal.matchApplied(tree).map(x => (x.tpt, x.args)) + def unapply(x: Applied)(given ctx: Context): Option[(TypeTree, List[Tree /*TypeTree | TypeBoundsTree*/])] = + Some((x.tpt, x.args)) } given AppliedOps: (self: Applied) { @@ -958,19 +992,20 @@ trait TreeOps extends Core { def args(given ctx: Context): List[Tree /*TypeTree | TypeBoundsTree*/] = internal.Applied_args(self) } - object IsAnnotated { - /** Matches any Annotated and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[Annotated] = - internal.matchAnnotated(tree) - } + given (given Context): IsInstanceOf[Annotated] = + internal.isInstanceOfAnnotated + + object IsAnnotated + @deprecated("Use _: Annotated", "") + def unapply(x: Annotated): Some[Annotated] = Some(x) object Annotated { def apply(arg: TypeTree, annotation: Term)(given ctx: Context): Annotated = internal.Annotated_apply(arg, annotation) def copy(original: Tree)(arg: TypeTree, annotation: Term)(given ctx: Context): Annotated = internal.Annotated_copy(original)(arg, annotation) - def unapply(tree: Tree)(given ctx: Context): Option[(TypeTree, Term)] = - internal.matchAnnotated(tree).map(x => (x.arg, x.annotation)) + def unapply(x: Annotated)(given ctx: Context): Option[(TypeTree, Term)] = + Some((x.arg, x.annotation)) } given AnnotatedOps: (self: Annotated) { @@ -978,19 +1013,20 @@ trait TreeOps extends Core { def annotation(given ctx: Context): Term = internal.Annotated_annotation(self) } - object IsMatchTypeTree { - /** Matches any MatchTypeTree and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[MatchTypeTree] = - internal.matchMatchTypeTree(tree) - } + given (given Context): IsInstanceOf[MatchTypeTree] = + internal.isInstanceOfMatchTypeTree + + object IsMatchTypeTree + @deprecated("Use _: MatchTypeTree", "") + def unapply(x: MatchTypeTree): Some[MatchTypeTree] = Some(x) object MatchTypeTree { def apply(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(given ctx: Context): MatchTypeTree = internal.MatchTypeTree_apply(bound, selector, cases) def copy(original: Tree)(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef])(given ctx: Context): MatchTypeTree = internal.MatchTypeTree_copy(original)(bound, selector, cases) - def unapply(tree: Tree)(given ctx: Context): Option[(Option[TypeTree], TypeTree, List[TypeCaseDef])] = - internal.matchMatchTypeTree(tree).map(x => (x.bound, x.selector, x.cases)) + def unapply(x: MatchTypeTree)(given ctx: Context): Option[(Option[TypeTree], TypeTree, List[TypeCaseDef])] = + Some((x.bound, x.selector, x.cases)) } given MatchTypeTreeOps: (self: MatchTypeTree) { @@ -999,38 +1035,39 @@ trait TreeOps extends Core { def cases(given ctx: Context): List[TypeCaseDef] = internal.MatchTypeTree_cases(self) } - object IsByName { - /** Matches any ByName and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[ByName] = - internal.matchByName(tree) - } + given (given Context): IsInstanceOf[ByName] = + internal.isInstanceOfByName + + object IsByName + @deprecated("Use _: ByName", "") + def unapply(x: ByName): Some[ByName] = Some(x) object ByName { def apply(result: TypeTree)(given ctx: Context): ByName = internal.ByName_apply(result) def copy(original: Tree)(result: TypeTree)(given ctx: Context): ByName = internal.ByName_copy(original)(result) - def unapply(tree: Tree)(given ctx: Context): Option[TypeTree] = - internal.matchByName(tree).map(_.result) + def unapply(x: ByName)(given ctx: Context): Option[TypeTree] = + Some(x.result) } given ByNameOps: (self: ByName) { def result(given ctx: Context): TypeTree = internal.ByName_result(self) } - object IsLambdaTypeTree { - /** Matches any LambdaTypeTree and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[LambdaTypeTree] = - internal.matchLambdaTypeTree(tree) - } + given (given Context): IsInstanceOf[LambdaTypeTree] = internal.isInstanceOfLambdaTypeTree + + object IsLambdaTypeTree + @deprecated("Use _: LambdaTypeTree", "") + def unapply(x: LambdaTypeTree): Some[LambdaTypeTree] = Some(x) object LambdaTypeTree { def apply(tparams: List[TypeDef], body: Tree /*TypeTree | TypeBoundsTree*/)(given ctx: Context): LambdaTypeTree = internal.Lambdaapply(tparams, body) def copy(original: Tree)(tparams: List[TypeDef], body: Tree /*TypeTree | TypeBoundsTree*/)(given ctx: Context): LambdaTypeTree = internal.Lambdacopy(original)(tparams, body) - def unapply(tree: Tree)(given ctx: Context): Option[(List[TypeDef], Tree /*TypeTree | TypeBoundsTree*/)] = - internal.matchLambdaTypeTree(tree).map(x => (x.tparams, x.body)) + def unapply(tree: LambdaTypeTree)(given ctx: Context): Option[(List[TypeDef], Tree /*TypeTree | TypeBoundsTree*/)] = + Some((tree.tparams, tree.body)) } given LambdaTypeTreeOps: (self: LambdaTypeTree) { @@ -1038,18 +1075,18 @@ trait TreeOps extends Core { def body(given ctx: Context): Tree /*TypeTree | TypeBoundsTree*/ = internal.Lambdabody(self) } - object IsTypeBind { - /** Matches any TypeBind and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[TypeBind] = - internal.matchTypeBind(tree) - } + given (given Context): IsInstanceOf[TypeBind] = internal.isInstanceOfTypeBind + + object IsTypeBind + @deprecated("Use _: TypeBind", "") + def unapply(x: TypeBind): Some[TypeBind] = Some(x) object TypeBind { // TODO def apply(name: String, tree: Tree)(given ctx: Context): TypeBind def copy(original: Tree)(name: String, tpt: Tree /*TypeTree | TypeBoundsTree*/)(given ctx: Context): TypeBind = internal.TypeBind_copy(original)(name, tpt) - def unapply(tree: Tree)(given ctx: Context): Option[(String, Tree /*TypeTree | TypeBoundsTree*/)] = - internal.matchTypeBind(tree).map(x => (x.name, x.body)) + def unapply(x: TypeBind)(given ctx: Context): Option[(String, Tree /*TypeTree | TypeBoundsTree*/)] = + Some((x.name, x.body)) } given TypeBindOps: (self: TypeBind) { @@ -1057,19 +1094,19 @@ trait TreeOps extends Core { def body(given ctx: Context): Tree /*TypeTree | TypeBoundsTree*/ = internal.TypeBind_body(self) } - object IsTypeBlock { - /** Matches any TypeBlock and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[TypeBlock] = - internal.matchTypeBlock(tree) - } + given (given Context): IsInstanceOf[TypeBlock] = internal.isInstanceOfTypeBlock + + object IsTypeBlock + @deprecated("Use _: TypeBlock", "") + def unapply(x: TypeBlock): Some[TypeBlock] = Some(x) object TypeBlock { def apply(aliases: List[TypeDef], tpt: TypeTree)(given ctx: Context): TypeBlock = internal.TypeBlock_apply(aliases, tpt) def copy(original: Tree)(aliases: List[TypeDef], tpt: TypeTree)(given ctx: Context): TypeBlock = internal.TypeBlock_copy(original)(aliases, tpt) - def unapply(tree: Tree)(given ctx: Context): Option[(List[TypeDef], TypeTree)] = - internal.matchTypeBlock(tree).map(x => (x.aliases, x.tpt)) + def unapply(x: TypeBlock)(given ctx: Context): Option[(List[TypeDef], TypeTree)] = + Some((x.aliases, x.tpt)) } given TypeBlockOps: (self: TypeBlock) { @@ -1085,30 +1122,31 @@ trait TreeOps extends Core { def hi(given ctx: Context): TypeTree = internal.TypeBoundsTree_hi(self) } - object IsTypeBoundsTree { - def unapply(tree: Tree)(given ctx: Context): Option[TypeBoundsTree] = - internal.matchTypeBoundsTree(tree) - } + given (given Context): IsInstanceOf[TypeBoundsTree] = internal.isInstanceOfTypeBoundsTree + + object IsTypeBoundsTree + @deprecated("Use _: TypeBoundsTree", "") + def unapply(x: TypeBoundsTree): Some[TypeBoundsTree] = Some(x) object TypeBoundsTree { - def unapply(tree: Tree)(given ctx: Context): Option[(TypeTree, TypeTree)] = - internal.matchTypeBoundsTree(tree).map(x => (x.low, x.hi)) + def unapply(x: TypeBoundsTree)(given ctx: Context): Option[(TypeTree, TypeTree)] = + Some((x.low, x.hi)) } given WildcardTypeTreeOps: (self: WildcardTypeTree) { def tpe(given ctx: Context): TypeOrBounds = internal.WildcardTypeTree_tpe(self) } - object IsWildcardTypeTree { - def unapply(tree: Tree)(given ctx: Context): Option[WildcardTypeTree] = - internal.matchWildcardTypeTree(tree) - } + given (given Context): IsInstanceOf[WildcardTypeTree] = internal.isInstanceOfWildcardTypeTree /** TypeBoundsTree containing wildcard type bounds */ + object IsWildcardTypeTree + @deprecated("Use _: WildcardTypeTree", "") + def unapply(x: WildcardTypeTree): Some[WildcardTypeTree] = Some(x) + object WildcardTypeTree { /** Matches a TypeBoundsTree containing wildcard type bounds */ - def unapply(tree: Tree)(given ctx: Context): Boolean = - internal.matchWildcardTypeTree(tree).isDefined + def unapply(x: WildcardTypeTree)(given ctx: Context): Boolean = true } // ----- CaseDefs ------------------------------------------------ @@ -1119,10 +1157,11 @@ trait TreeOps extends Core { def rhs(given ctx: Context): Term = internal.CaseDef_rhs(caseDef) } - object IsCaseDef { - def unapply(self: Tree)(given ctx: Context): Option[CaseDef] = - internal.matchCaseDef(self) - } + given (given Context): IsInstanceOf[CaseDef] = internal.isInstanceOfCaseDef + + object IsCaseDef + @deprecated("Use _: CaseDef", "") + def unapply(x: CaseDef): Some[CaseDef] = Some(x) object CaseDef { def apply(pattern: Tree, guard: Option[Term], rhs: Term)(given ctx: Context): CaseDef = @@ -1131,8 +1170,8 @@ trait TreeOps extends Core { def copy(original: Tree)(pattern: Tree, guard: Option[Term], rhs: Term)(given ctx: Context): CaseDef = internal.CaseDef_module_copy(original)(pattern, guard, rhs) - def unapply(tree: Tree)(given ctx: Context): Option[(Tree, Option[Term], Term)] = - internal.matchCaseDef(tree).map( x => (x.pattern, x.guard, x.rhs)) + def unapply(x: CaseDef)(given ctx: Context): Option[(Tree, Option[Term], Term)] = + Some((x.pattern, x.guard, x.rhs)) } given TypeCaseDefOps: (caseDef: TypeCaseDef) { @@ -1140,10 +1179,12 @@ trait TreeOps extends Core { def rhs(given ctx: Context): TypeTree = internal.TypeCaseDef_rhs(caseDef) } - object IsTypeCaseDef { - def unapply(self: Tree)(given ctx: Context): Option[TypeCaseDef] = - internal.matchTypeCaseDef(self) - } + given (given Context): IsInstanceOf[TypeCaseDef] = + internal.isInstanceOfTypeCaseDef + + object IsTypeCaseDef + @deprecated("Use _: TypeCaseDef", "") + def unapply(x: TypeCaseDef): Some[TypeCaseDef] = Some(x) object TypeCaseDef { def apply(pattern: TypeTree, rhs: TypeTree)(given ctx: Context): TypeCaseDef = @@ -1152,23 +1193,24 @@ trait TreeOps extends Core { def copy(original: Tree)(pattern: TypeTree, rhs: TypeTree)(given ctx: Context): TypeCaseDef = internal.TypeCaseDef_module_copy(original)(pattern, rhs) - def unapply(tree: Tree)(given ctx: Context): Option[(TypeTree, TypeTree)] = - internal.matchTypeCaseDef(tree).map( x => (x.pattern, x.rhs)) + def unapply(tree: TypeCaseDef)(given ctx: Context): Option[(TypeTree, TypeTree)] = + Some((tree.pattern, tree.rhs)) } // ----- Trees ------------------------------------------------ - object IsBind { - def unapply(pattern: Tree)(given ctx: Context): Option[Bind] = - internal.matchTree_Bind(pattern) - } + given (given Context): IsInstanceOf[Bind] = internal.isInstanceOfBind + + object IsBind + @deprecated("Use _: Bind", "") + def unapply(x: Bind): Some[Bind] = Some(x) object Bind { // TODO def apply(name: String, pattern: Tree)(given ctx: Context): Bind def copy(original: Tree)(name: String, pattern: Tree)(given ctx: Context): Bind = internal.Tree_Bind_module_copy(original)(name, pattern) - def unapply(pattern: Tree)(given ctx: Context): Option[(String, Tree)] = - internal.matchTree_Bind(pattern).map(x => (x.name, x.pattern)) + def unapply(pattern: Bind)(given ctx: Context): Option[(String, Tree)] = + Some((pattern.name, pattern.pattern)) } given BindOps: (bind: Bind) { @@ -1176,17 +1218,18 @@ trait TreeOps extends Core { def pattern(given ctx: Context): Tree = internal.Tree_Bind_pattern(bind) } - object IsUnapply { - def unapply(pattern: Tree)(given ctx: Context): Option[Unapply] = - internal.matchTree_Unapply(pattern) - } + given (given Context): IsInstanceOf[Unapply] = internal.isInstanceOfUnapply + + object IsUnapply + @deprecated("Use _: Unapply", "") + def unapply(x: Unapply): Some[Unapply] = Some(x) object Unapply { // TODO def apply(fun: Term, implicits: List[Term], patterns: List[Tree])(given ctx: Context): Unapply def copy(original: Tree)(fun: Term, implicits: List[Term], patterns: List[Tree])(given ctx: Context): Unapply = internal.Tree_Unapply_module_copy(original)(fun, implicits, patterns) - def unapply(pattern: Tree)(given ctx: Context): Option[(Term, List[Term], List[Tree])] = - internal.matchTree_Unapply(pattern).map(x => (x.fun, x.implicits, x.patterns)) + def unapply(x: Unapply)(given ctx: Context): Option[(Term, List[Term], List[Tree])] = + Some((x.fun, x.implicits, x.patterns)) } given UnapplyOps: (unapply: Unapply) { @@ -1195,18 +1238,19 @@ trait TreeOps extends Core { def patterns(given ctx: Context): List[Tree] = internal.Tree_Unapply_patterns(unapply) } - object IsAlternatives { - def unapply(pattern: Tree)(given ctx: Context): Option[Alternatives] = - internal.matchTree_Alternatives(pattern) - } + given (given Context): IsInstanceOf[Alternatives] = internal.isInstanceOfAlternatives + + object IsAlternatives + @deprecated("Use _: Alternatives", "") + def unapply(x: Alternatives): Some[Alternatives] = Some(x) object Alternatives { def apply(patterns: List[Tree])(given ctx: Context): Alternatives = internal.Tree_Alternatives_module_apply(patterns) def copy(original: Tree)(patterns: List[Tree])(given ctx: Context): Alternatives = internal.Tree_Alternatives_module_copy(original)(patterns) - def unapply(pattern: Tree)(given ctx: Context): Option[List[Tree]] = - internal.matchTree_Alternatives(pattern).map(_.patterns) + def unapply(x: Alternatives)(given ctx: Context): Option[List[Tree]] = + Some(x.patterns) } given AlternativesOps: (alternatives: Alternatives) { diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala index 498aaae38f40..995cbce8b85c 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala @@ -63,42 +63,45 @@ trait TypeOrBoundsOps extends Core { def isDependentFunctionType(given ctx: Context): Boolean = internal.Type_isDependentFunctionType(self) } - object IsType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[Type] = - internal.matchType(typeOrBounds) - } + // FIXME: needs #7532 fixed in the reference compiler + // given (given Context): IsInstanceOf[Type] = internal.isInstanceOfType + + object IsType + // FIXME: Add depecation. Needs #7532 fixed in the reference compiler + // @deprecated("Use _: Type", "") + def unapply(x: TypeOrBounds)(given ctx: Context): Option[Type] = + internal.isInstanceOfType.unapply(x) 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) - } + given (given Context): IsInstanceOf[ConstantType] = internal.isInstanceOfConstantType + + object IsConstantType + @deprecated("Use _: ConstantType", "") + def unapply(x: ConstantType)(given ctx: Context): Option[ConstantType] = Some(x) object ConstantType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[Constant] = - internal.matchConstantType(typeOrBounds).map(_.constant) + def unapply(x: ConstantType)(given ctx: Context): Option[Constant] = Some(x.constant) } given ConstantTypeOps: (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] = - internal.matchTermRef(tpe) - } + given (given Context): IsInstanceOf[TermRef] = internal.isInstanceOfTermRef + + object IsTermRef + @deprecated("Use _: TermRef", "") + def unapply(x: TermRef)(given ctx: Context): Option[TermRef] = Some(x) 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)) + def unapply(x: TermRef)(given ctx: Context): Option[(TypeOrBounds /* Type | NoPrefix */, String)] = + Some((x.qualifier, x.name)) } given TermRefOps: (self: TermRef) { @@ -106,15 +109,15 @@ trait TypeOrBoundsOps extends Core { 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] = - internal.matchTypeRef(tpe) - } + given (given Context): IsInstanceOf[TypeRef] = internal.isInstanceOfTypeRef + + object IsTypeRef + @deprecated("Use _: TypeRef", "") + def unapply(x: TypeRef)(given ctx: Context): Option[TypeRef] = Some(x) object TypeRef { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(TypeOrBounds /* Type | NoPrefix */, String)] = - internal.matchTypeRef(typeOrBounds).map(x => (x.qualifier, x.name)) + def unapply(x: TypeRef)(given ctx: Context): Option[(TypeOrBounds /* Type | NoPrefix */, String)] = + Some((x.qualifier, x.name)) } given TypeRefOps: (self: TypeRef) { @@ -122,15 +125,15 @@ trait TypeOrBoundsOps extends Core { 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] = - internal.matchSuperType(tpe) - } + given (given Context): IsInstanceOf[SuperType] = internal.isInstanceOfSuperType + + object IsSuperType + @deprecated("Use _: SuperType", "") + def unapply(x: SuperType)(given ctx: Context): Option[SuperType] = Some(x) object SuperType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Type)] = - internal.matchSuperType(typeOrBounds).map(x => (x.thistpe, x.supertpe)) + def unapply(x: SuperType)(given ctx: Context): Option[(Type, Type)] = + Some((x.thistpe, x.supertpe)) } given SuperTypeOps: (self: SuperType) { @@ -138,15 +141,15 @@ trait TypeOrBoundsOps extends Core { 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] = - internal.matchRefinement(tpe) - } + given (given Context): IsInstanceOf[Refinement] = internal.isInstanceOfRefinement + + object IsRefinement + @deprecated("Use _: Refinement", "") + def unapply(x: Refinement)(given ctx: Context): Option[Refinement] = Some(x) 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)) + def unapply(x: Refinement)(given ctx: Context): Option[(Type, String, TypeOrBounds /* Type | TypeBounds */)] = + Some((x.parent, x.name, x.info)) } given RefinementOps: (self: Refinement) { @@ -155,17 +158,17 @@ trait TypeOrBoundsOps extends Core { 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] = - internal.matchAppliedType(tpe) - } + given (given Context): IsInstanceOf[AppliedType] = internal.isInstanceOfAppliedType + + object IsAppliedType + @deprecated("Use _: AppliedType", "") + def unapply(x: AppliedType)(given ctx: Context): Option[AppliedType] = Some(x) 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)) + def unapply(x: AppliedType)(given ctx: Context): Option[(Type, List[TypeOrBounds /* Type | TypeBounds */])] = + Some((x.tycon, x.args)) } given AppliedTypeOps: (self: AppliedType) { @@ -173,15 +176,15 @@ trait TypeOrBoundsOps extends Core { 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] = - internal.matchAnnotatedType(tpe) - } + given (given Context): IsInstanceOf[AnnotatedType] = internal.isInstanceOfAnnotatedType + + object IsAnnotatedType + @deprecated("Use _: AnnotatedType", "") + def unapply(x: AnnotatedType)(given ctx: Context): Option[AnnotatedType] = Some(x) object AnnotatedType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Term)] = - internal.matchAnnotatedType(typeOrBounds).map(x => (x.underlying, x.annot)) + def unapply(x: AnnotatedType)(given ctx: Context): Option[(Type, Term)] = + Some((x.underlying, x.annot)) } given AnnotatedTypeOps: (self: AnnotatedType) { @@ -189,15 +192,15 @@ trait TypeOrBoundsOps extends Core { 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] = - internal.matchAndType(tpe) - } + given (given Context): IsInstanceOf[AndType] = internal.isInstanceOfAndType + + object IsAndType + @deprecated("Use _: AndType", "") + def unapply(x: AndType)(given ctx: Context): Option[AndType] = Some(x) object AndType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Type)] = - internal.matchAndType(typeOrBounds).map(x => (x.left, x.right)) + def unapply(x: AndType)(given ctx: Context): Option[(Type, Type)] = + Some((x.left, x.right)) } given AndTypeOps: (self: AndType) { @@ -205,15 +208,15 @@ trait TypeOrBoundsOps extends Core { 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] = - internal.matchOrType(tpe) - } + given (given Context): IsInstanceOf[OrType] = internal.isInstanceOfOrType + + object IsOrType + @deprecated("Use _: OrType", "") + def unapply(x: OrType)(given ctx: Context): Option[OrType] = Some(x) object OrType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Type)] = - internal.matchOrType(typeOrBounds).map(x => (x.left, x.right)) + def unapply(x: OrType)(given ctx: Context): Option[(Type, Type)] = + Some((x.left, x.right)) } given OrTypeOps: (self: OrType) { @@ -221,15 +224,15 @@ trait TypeOrBoundsOps extends Core { 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] = - internal.matchMatchType(tpe) - } + given (given Context): IsInstanceOf[MatchType] = internal.isInstanceOfMatchType + + object IsMatchType + @deprecated("Use _: MatchType", "") + def unapply(x: MatchType)(given ctx: Context): Option[MatchType] = Some(x) 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)) + def unapply(x: MatchType)(given ctx: Context): Option[(Type, Type, List[Type])] = + Some((x.bound, x.scrutinee, x.cases)) } given MatchTypeOps: (self: MatchType) { @@ -238,30 +241,29 @@ trait TypeOrBoundsOps extends Core { 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] = - internal.matchByNameType(tpe) - } + given (given Context): IsInstanceOf[ByNameType] = internal.isInstanceOfByNameType + + object IsByNameType + @deprecated("Use _: ByNameType", "") + def unapply(x: ByNameType)(given ctx: Context): Option[ByNameType] = Some(x) object ByNameType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[Type] = - internal.matchByNameType(typeOrBounds).map(_.underlying) + def unapply(x: ByNameType)(given ctx: Context): Option[Type] = Some(x.underlying) } given ByNameTypeOps: (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] = - internal.matchParamRef(tpe) - } + given (given Context): IsInstanceOf[ParamRef] = internal.isInstanceOfParamRef + + object IsParamRef + @deprecated("Use _: ParamRef", "") + def unapply(x: ParamRef)(given ctx: Context): Option[ParamRef] = Some(x) object ParamRef { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(LambdaType[TypeOrBounds], Int)] = - internal.matchParamRef(typeOrBounds).map(x => (x.binder, x.paramNum)) + def unapply(x: ParamRef)(given ctx: Context): Option[(LambdaType[TypeOrBounds], Int)] = + Some((x.binder, x.paramNum)) } given ParamRefOps: (self: ParamRef) { @@ -269,60 +271,57 @@ trait TypeOrBoundsOps extends Core { 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] = - internal.matchThisType(tpe) - } + given (given Context): IsInstanceOf[ThisType] = internal.isInstanceOfThisType + + object IsThisType + @deprecated("Use _: ThisType", "") + def unapply(x: ThisType)(given ctx: Context): Option[ThisType] = Some(x) object ThisType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[Type] = - internal.matchThisType(typeOrBounds).map(_.tref) + def unapply(x: ThisType)(given ctx: Context): Option[Type] = Some(x.tref) } given ThisTypeOps: (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] = - internal.matchRecursiveThis(tpe) - } + given (given Context): IsInstanceOf[RecursiveThis] = internal.isInstanceOfRecursiveThis + + object IsRecursiveThis + @deprecated("Use _: RecursiveThis", "") + def unapply(x: RecursiveThis)(given ctx: Context): Option[RecursiveThis] = Some(x) object RecursiveThis { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[RecursiveType] = - internal.matchRecursiveThis(typeOrBounds).map(_.binder) + def unapply(x: RecursiveThis)(given ctx: Context): Option[RecursiveType] = Some(x.binder) } given RecursiveThisOps: (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] = - internal.matchRecursiveType(tpe) - } + given (given Context): IsInstanceOf[RecursiveType] = internal.isInstanceOfRecursiveType + + object IsRecursiveType + @deprecated("Use _: RecursiveType", "") + def unapply(x: RecursiveType)(given ctx: Context): Option[RecursiveType] = Some(x) object RecursiveType { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[Type] = - internal.matchRecursiveType(typeOrBounds).map(_.underlying) + def unapply(x: RecursiveType)(given ctx: Context): Option[Type] = Some(x.underlying) } given RecursiveTypeOps: (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] = - internal.matchMethodType(tpe) - } + given (given Context): IsInstanceOf[MethodType] = internal.isInstanceOfMethodType + + object IsMethodType + @deprecated("Use _: MethodType", "") + def unapply(x: MethodType)(given ctx: Context): Option[MethodType] = Some(x) 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)) + def unapply(x: MethodType)(given ctx: Context): Option[(List[String], List[Type], Type)] = + Some((x.paramNames, x.paramTypes, x.resType)) } given MethodTypeOps: (self: MethodType) { @@ -333,15 +332,15 @@ trait TypeOrBoundsOps extends Core { 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] = - internal.matchPolyType(tpe) - } + given (given Context): IsInstanceOf[PolyType] = internal.isInstanceOfPolyType + + object IsPolyType + @deprecated("Use _: PolyType", "") + def unapply(x: PolyType)(given ctx: Context): Option[PolyType] = Some(x) 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)) + def unapply(x: PolyType)(given ctx: Context): Option[(List[String], List[TypeBounds], Type)] = + Some((x.paramNames, x.paramBounds, x.resType)) } given PolyTypeOps: (self: PolyType) { @@ -350,15 +349,15 @@ trait TypeOrBoundsOps extends Core { 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] = - internal.matchTypeLambda(tpe) - } + given (given Context): IsInstanceOf[TypeLambda] = internal.isInstanceOfTypeLambda + + object IsTypeLambda + @deprecated("Use _: TypeLambda", "") + def unapply(x: TypeLambda)(given ctx: Context): Option[TypeLambda] = Some(x) 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)) + def unapply(x: TypeLambda)(given ctx: Context): Option[(List[String], List[TypeBounds], Type)] = + Some((x.paramNames, x.paramBounds, x.resType)) } given TypeLambdaOps: (self: TypeLambda) { @@ -369,14 +368,14 @@ trait TypeOrBoundsOps extends Core { // ----- TypeBounds ----------------------------------------------- - object IsTypeBounds { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[TypeBounds] = - internal.matchTypeBounds(typeOrBounds) - } + given (given Context): IsInstanceOf[TypeBounds] = internal.isInstanceOfTypeBounds + + object IsTypeBounds + @deprecated("Use _: TypeBounds", "") + def unapply(x: TypeBounds)(given ctx: Context): Option[TypeBounds] = Some(x) object TypeBounds { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Option[(Type, Type)] = - internal.matchTypeBounds(typeOrBounds).map(x => (x.low, x.hi)) + def unapply(x: TypeBounds)(given ctx: Context): Option[(Type, Type)] = Some((x.low, x.hi)) } given TypeBoundsOps: (self: TypeBounds) { @@ -386,9 +385,9 @@ trait TypeOrBoundsOps extends Core { // ----- NoPrefix ------------------------------------------------- - object NoPrefix { - def unapply(typeOrBounds: TypeOrBounds)(given ctx: Context): Boolean = - internal.matchNoPrefix(typeOrBounds).isDefined - } + given (given Context): IsInstanceOf[NoPrefix] = internal.isInstanceOfNoPrefix + + object NoPrefix + def unapply(x: NoPrefix)(given ctx: Context): Boolean = true } diff --git a/tests/neg-macros/i6976/Macro_1.scala b/tests/neg-macros/i6976/Macro_1.scala index f8df371e9032..7741617ec781 100644 --- a/tests/neg-macros/i6976/Macro_1.scala +++ b/tests/neg-macros/i6976/Macro_1.scala @@ -8,7 +8,7 @@ object macros { inline def mcr(x: => Any) = ${mcrImpl('x)} def mcrImpl(body: Expr[Any])(given ctx: QuoteContext): Expr[Any] = { - import ctx.tasty._ + import ctx.tasty.{_, given} body.unseal match { case Block(_, _) => '{2} } } } diff --git a/tests/pos-special/fatal-warnings/tasty-parent-unapply.scala b/tests/pos-special/fatal-warnings/tasty-parent-unapply.scala index af86983884fe..4ca6e836afa2 100644 --- a/tests/pos-special/fatal-warnings/tasty-parent-unapply.scala +++ b/tests/pos-special/fatal-warnings/tasty-parent-unapply.scala @@ -6,7 +6,7 @@ object Macros { def impl(reflect: Reflection): Unit = { - import reflect._ + import reflect.{_, given} def foo(tree: Tree, term: Term, typeTree: TypeTree, parent: Tree) = { diff --git a/tests/pos/i7204.scala b/tests/pos/i7204.scala new file mode 100644 index 000000000000..95e76848c800 --- /dev/null +++ b/tests/pos/i7204.scala @@ -0,0 +1,8 @@ +import scala.quoted._ + +object Foo { + def impl(given qctx: QuoteContext): Unit = { + import qctx.tasty.{_, given} + val Select(_, _) = (??? : Term) + } +} diff --git a/tests/run-macros/i5715/Macro_1.scala b/tests/run-macros/i5715/Macro_1.scala index 0eea998edf3b..a1205573b5a6 100644 --- a/tests/run-macros/i5715/Macro_1.scala +++ b/tests/run-macros/i5715/Macro_1.scala @@ -8,8 +8,7 @@ object scalatest { import qctx.tasty.{_, given} cond.unseal.underlyingArgument match { - case app @ Apply(sel @ Select(lhs, op), rhs :: Nil) => - val IsSelect(select) = sel + case app @ Apply(select @ Select(lhs, op), rhs :: Nil) => val cond = Apply(Select.copy(select)(lhs, "exists"), rhs :: Nil).seal.cast[Boolean] '{ scala.Predef.assert($cond) } case _ => diff --git a/tests/run-macros/i6171/Macro_1.scala b/tests/run-macros/i6171/Macro_1.scala index 7a64dd649f78..1cae0f9667f6 100644 --- a/tests/run-macros/i6171/Macro_1.scala +++ b/tests/run-macros/i6171/Macro_1.scala @@ -8,8 +8,10 @@ object scalatest { import qctx.tasty.{_, given} import util._ - def isImplicitMethodType(tp: Type): Boolean = - IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty + def isImplicitMethodType(tp: Type): Boolean = tp match + case tp: MethodType => tp.isImplicit + case _ => false + 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 7d00825d1025..5f8dd23f64fc 100644 --- a/tests/run-macros/reflect-dsl/assert_1.scala +++ b/tests/run-macros/reflect-dsl/assert_1.scala @@ -8,8 +8,9 @@ object scalatest { import qctx.tasty.{_, given} import util._ - def isImplicitMethodType(tp: Type): Boolean = - IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty + def isImplicitMethodType(tp: Type): Boolean = tp match + case tp: MethodType => tp.isImplicit + case _ => false 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 fb5e8b70e619..8738d4694206 100644 --- a/tests/run-macros/reflect-select-constructor/assert_1.scala +++ b/tests/run-macros/reflect-select-constructor/assert_1.scala @@ -8,8 +8,9 @@ object scalatest { import qctx.tasty.{_, given} import util._ - def isImplicitMethodType(tp: Type): Boolean = - IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty + def isImplicitMethodType(tp: Type): Boolean = tp match + case tp: MethodType => tp.isImplicit + case _ => false cond.unseal.underlyingArgument match { case t @ Apply(Select(lhs, op), rhs :: Nil) => diff --git a/tests/run-macros/reflect-select-copy/reflect-select-copy/assert_1.scala b/tests/run-macros/reflect-select-copy-2/assert_1.scala similarity index 82% rename from tests/run-macros/reflect-select-copy/reflect-select-copy/assert_1.scala rename to tests/run-macros/reflect-select-copy-2/assert_1.scala index d428ede4c8cf..4293a6a29d1a 100644 --- a/tests/run-macros/reflect-select-copy/reflect-select-copy/assert_1.scala +++ b/tests/run-macros/reflect-select-copy-2/assert_1.scala @@ -8,8 +8,9 @@ object scalatest { import qctx.tasty.{_, given} import util._ - def isImplicitMethodType(tp: Type): Boolean = - Type.IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty + def isImplicitMethodType(tp: Type): Boolean = tp match + case tp: MethodType => tp.isImplicit + case _ => false cond.unseal.underlyingArgument match { case Apply(sel @ Select(lhs, op), rhs :: Nil) => @@ -24,7 +25,7 @@ object scalatest { } } }.seal.cast[Unit] - case Apply(f @ Apply(IsSelect(sel @ Select(Apply(qual, lhs :: Nil), op)), rhs :: Nil), implicits) + case Apply(f @ Apply(sel @ Select(Apply(qual, lhs :: Nil), op), rhs :: Nil), implicits) if isImplicitMethodType(f.tpe) => let(lhs) { left => let(rhs) { right => diff --git a/tests/run-macros/reflect-select-copy/reflect-select-copy/test_2.scala b/tests/run-macros/reflect-select-copy-2/test_2.scala similarity index 100% rename from tests/run-macros/reflect-select-copy/reflect-select-copy/test_2.scala rename to tests/run-macros/reflect-select-copy-2/test_2.scala diff --git a/tests/run-macros/reflect-select-copy/assert_1.scala b/tests/run-macros/reflect-select-copy/assert_1.scala index 03a9e8ccede2..0a5ed60b5149 100644 --- a/tests/run-macros/reflect-select-copy/assert_1.scala +++ b/tests/run-macros/reflect-select-copy/assert_1.scala @@ -8,8 +8,7 @@ object scalatest { import qctx.tasty.{_, given} cond.unseal.underlyingArgument match { - case Apply(sel @ Select(lhs, op), rhs :: Nil) => - val IsSelect(select) = sel + case Apply(select @ Select(lhs, op), rhs :: Nil) => val cond = Apply(Select.copy(select)(lhs, ">"), rhs :: Nil).seal.cast[Boolean] '{ scala.Predef.assert($cond) } case _ => 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 028788c865ad..e8e8936ae0de 100644 --- a/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala +++ b/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala @@ -8,8 +8,9 @@ object scalatest { import qctx.tasty.{_, given} import util._ - def isImplicitMethodType(tp: Type): Boolean = - IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty + def isImplicitMethodType(tp: Type): Boolean = tp match + case tp: MethodType => tp.isImplicit + case _ => false 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 fb5e8b70e619..8738d4694206 100644 --- a/tests/run-macros/reflect-select-value-class/assert_1.scala +++ b/tests/run-macros/reflect-select-value-class/assert_1.scala @@ -8,8 +8,9 @@ object scalatest { import qctx.tasty.{_, given} import util._ - def isImplicitMethodType(tp: Type): Boolean = - IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty + def isImplicitMethodType(tp: Type): Boolean = tp match + case tp: MethodType => tp.isImplicit + case _ => false cond.unseal.underlyingArgument match { case t @ Apply(Select(lhs, op), rhs :: Nil) => diff --git a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TastyInterpreter.scala b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TastyInterpreter.scala index 6484db2e512e..9a1bdd9c6c64 100644 --- a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TastyInterpreter.scala +++ b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TastyInterpreter.scala @@ -6,7 +6,7 @@ import scala.tasty.file.TastyConsumer class TastyInterpreter extends TastyConsumer { final def apply(reflect: Reflection)(root: reflect.Tree): Unit = { - import reflect._ + import reflect.{_, given} object Traverser extends TreeTraverser { override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = tree match { diff --git a/tests/run-with-compiler/tasty-consumer/Test.scala b/tests/run-with-compiler/tasty-consumer/Test.scala index 8a803c68d8c4..ecbde79572e6 100644 --- a/tests/run-with-compiler/tasty-consumer/Test.scala +++ b/tests/run-with-compiler/tasty-consumer/Test.scala @@ -10,11 +10,11 @@ object Test { class DBConsumer extends TastyConsumer { final def apply(reflect: Reflection)(root: reflect.Tree): Unit = { - import reflect._ + import reflect.{_, given} object Traverser extends TreeTraverser { override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = tree match { - case IsDefinition(tree) => + case tree: Definition => println(tree.showExtractors) super.traverseTree(tree) case tree => From 3e658c46c9a152c69cde43eeef669cf06d41a4b2 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 18 Nov 2019 21:19:51 +0100 Subject: [PATCH 2/3] Use isClassDef --- .../tools/dotc/tastyreflect/ReflectionCompilerInterface.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala index a44dd735f5a0..45484d65d950 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala @@ -196,7 +196,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend def isInstanceOfTypeDef(given ctx: Context): IsInstanceOf[TypeDef] = new { def runtimeClass: Class[?] = classOf[TypeDef] override def unapply(x: Any): Option[TypeDef] = x match - case x: tpd.TypeDef if !x.symbol.isClass => Some(x) + case x: tpd.TypeDef if !x.isClassDef => Some(x) case _ => None } From 3798b6ff97f64be290d46310128fcc630508146d Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 18 Nov 2019 21:26:02 +0100 Subject: [PATCH 3/3] Update to given --- .../ReflectionCompilerInterface.scala | 14 +++++----- .../tasty/reflect/CompilerInterface.scala | 14 +++++----- library/src/scala/tasty/reflect/Core.scala | 6 ++-- .../tasty/reflect/ExtractorsPrinter.scala | 4 +-- .../tasty/reflect/SourceCodePrinter.scala | 4 +-- library/src/scala/tasty/reflect/TreeOps.scala | 28 +++++++++---------- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala index 45484d65d950..f0ae6c92b86b 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala @@ -617,21 +617,21 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend def Match_copy(original: Tree)(selector: Term, cases: List[CaseDef])(given Context): Match = tpd.cpy.Match(original)(selector, cases) - type ImpliedMatch = tpd.Match + type GivenMatch = tpd.Match - def isInstanceOfImpliedMatch(given ctx: Context): IsInstanceOf[ImpliedMatch] = new { - def runtimeClass: Class[?] = classOf[ImpliedMatch] - override def unapply(x: Any): Option[ImpliedMatch] = x match + def isInstanceOfGivenMatch(given ctx: Context): IsInstanceOf[GivenMatch] = new { + def runtimeClass: Class[?] = classOf[GivenMatch] + override def unapply(x: Any): Option[GivenMatch] = x match case x: tpd.Match if x.selector.isEmpty => Some(x) case _ => None } - def ImplicitMatch_cases(self: Match)(given Context): List[CaseDef] = self.cases + def GivenMatch_cases(self: Match)(given Context): List[CaseDef] = self.cases - def ImplicitMatch_apply(cases: List[CaseDef])(given Context): ImpliedMatch = + def GivenMatch_apply(cases: List[CaseDef])(given Context): GivenMatch = withDefaultPos(tpd.Match(tpd.EmptyTree, cases)) - def ImplicitMatch_copy(original: Tree)(cases: List[CaseDef])(given Context): ImpliedMatch = + def GivenMatch_copy(original: Tree)(cases: List[CaseDef])(given Context): GivenMatch = tpd.cpy.Match(original)(tpd.EmptyTree, cases) type Try = tpd.Try diff --git a/library/src/scala/tasty/reflect/CompilerInterface.scala b/library/src/scala/tasty/reflect/CompilerInterface.scala index b1abe512d948..32754b1cf41a 100644 --- a/library/src/scala/tasty/reflect/CompilerInterface.scala +++ b/library/src/scala/tasty/reflect/CompilerInterface.scala @@ -32,7 +32,7 @@ import scala.runtime.quoted.Unpickler * | +- Closure * | +- If * | +- Match - * | +- ImpliedMatch + * | +- GivenMatch * | +- Try * | +- Return * | +- Repeated @@ -466,15 +466,15 @@ trait CompilerInterface { def Match_apply(selector: Term, cases: List[CaseDef])(given ctx: Context): Match def Match_copy(original: Tree)(selector: Term, cases: List[CaseDef])(given ctx: Context): Match - /** Tree representing a pattern match `delegate match { ... }` in the source code */ - type ImpliedMatch <: Term + /** Tree representing a pattern match `given match { ... }` in the source code */ + type GivenMatch <: Term - def isInstanceOfImpliedMatch(given ctx: Context): IsInstanceOf[ImpliedMatch] + def isInstanceOfGivenMatch(given ctx: Context): IsInstanceOf[GivenMatch] - def ImplicitMatch_cases(self: ImpliedMatch)(given ctx: Context): List[CaseDef] + def GivenMatch_cases(self: GivenMatch)(given ctx: Context): List[CaseDef] - def ImplicitMatch_apply(cases: List[CaseDef])(given ctx: Context): ImpliedMatch - def ImplicitMatch_copy(original: Tree)(cases: List[CaseDef])(given ctx: Context): ImpliedMatch + def GivenMatch_apply(cases: List[CaseDef])(given ctx: Context): GivenMatch + def GivenMatch_copy(original: Tree)(cases: List[CaseDef])(given ctx: Context): GivenMatch /** Tree representing a tyr catch `try x catch { ... } finally { ... }` in the source code */ type Try <: Term diff --git a/library/src/scala/tasty/reflect/Core.scala b/library/src/scala/tasty/reflect/Core.scala index b6c5717db2c9..8c7648ed3c9f 100644 --- a/library/src/scala/tasty/reflect/Core.scala +++ b/library/src/scala/tasty/reflect/Core.scala @@ -29,7 +29,7 @@ package scala.tasty.reflect * | +- Closure * | +- If * | +- Match - * | +- ImpliedMatch + * | +- GivenMatch * | +- Try * | +- Return * | +- Repeated @@ -204,8 +204,8 @@ trait Core { /** Tree representing a pattern match `x match { ... }` in the source code */ type Match = internal.Match - /** Tree representing a pattern match `delegate match { ... }` in the source code */ // TODO: drop - type ImpliedMatch = internal.ImpliedMatch + /** Tree representing a pattern match `given match { ... }` in the source code */ // TODO: drop + type GivenMatch = internal.GivenMatch /** Tree representing a try catch `try x catch { ... } finally { ... }` in the source code */ type Try = internal.Try diff --git a/library/src/scala/tasty/reflect/ExtractorsPrinter.scala b/library/src/scala/tasty/reflect/ExtractorsPrinter.scala index 293eac1f76ef..d49eb0bf65ce 100644 --- a/library/src/scala/tasty/reflect/ExtractorsPrinter.scala +++ b/library/src/scala/tasty/reflect/ExtractorsPrinter.scala @@ -91,8 +91,8 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val tasty: R) extends Print this += "Closure(" += meth += ", " += tpt += ")" case Match(selector, cases) => this += "Match(" += selector += ", " ++= cases += ")" - case ImpliedMatch(cases) => - this += "ImpliedMatch(" ++= cases += ")" + case GivenMatch(cases) => + this += "GivenMatch(" ++= cases += ")" case Return(expr) => this += "Return(" += expr += ")" case While(cond, body) => diff --git a/library/src/scala/tasty/reflect/SourceCodePrinter.scala b/library/src/scala/tasty/reflect/SourceCodePrinter.scala index f8587ad8d829..aca2e76e1dc8 100644 --- a/library/src/scala/tasty/reflect/SourceCodePrinter.scala +++ b/library/src/scala/tasty/reflect/SourceCodePrinter.scala @@ -476,8 +476,8 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig this += highlightKeyword(" match") inBlock(printCases(cases, lineBreak())) - case ImpliedMatch(cases) => - this += highlightKeyword("delegate match") // TODO: drop + case GivenMatch(cases) => + this += highlightKeyword("given match") // TODO: drop inBlock(printCases(cases, lineBreak())) case Try(body, cases, finallyOpt) => diff --git a/library/src/scala/tasty/reflect/TreeOps.scala b/library/src/scala/tasty/reflect/TreeOps.scala index 743a1b377a07..fa8f771c82df 100644 --- a/library/src/scala/tasty/reflect/TreeOps.scala +++ b/library/src/scala/tasty/reflect/TreeOps.scala @@ -672,29 +672,29 @@ trait TreeOps extends Core { def cases(given ctx: Context): List[CaseDef] = internal.Match_cases(self) } - given (given Context): IsInstanceOf[ImpliedMatch] = internal.isInstanceOfImpliedMatch + given (given Context): IsInstanceOf[GivenMatch] = internal.isInstanceOfGivenMatch /** Scala implicit `match` term */ - object IsImpliedMatch - @deprecated("Use _: ImpliedMatch", "") - def unapply(x: ImpliedMatch): Some[ImpliedMatch] = Some(x) + object IsGivenMatch + @deprecated("Use _: GivenMatch", "") + def unapply(x: GivenMatch): Some[GivenMatch] = Some(x) - object ImpliedMatch { + object GivenMatch { - /** Creates a pattern match `delegate match { }` */ - def apply(cases: List[CaseDef])(given ctx: Context): ImpliedMatch = - internal.ImplicitMatch_apply(cases) + /** Creates a pattern match `given match { }` */ + def apply(cases: List[CaseDef])(given ctx: Context): GivenMatch = + internal.GivenMatch_apply(cases) - def copy(original: Tree)(cases: List[CaseDef])(given ctx: Context): ImpliedMatch = - internal.ImplicitMatch_copy(original)(cases) + def copy(original: Tree)(cases: List[CaseDef])(given ctx: Context): GivenMatch = + internal.GivenMatch_copy(original)(cases) - /** Matches a pattern match `delegate match { }` */ - def unapply(x: ImpliedMatch)(given ctx: Context): Option[List[CaseDef]] = Some(x.cases) + /** Matches a pattern match `given match { }` */ + def unapply(x: GivenMatch)(given ctx: Context): Option[List[CaseDef]] = Some(x.cases) } - given ImpliedMatchOps: (self: ImpliedMatch) { - def cases(given ctx: Context): List[CaseDef] = internal.ImplicitMatch_cases(self) + given GivenMatchOps: (self: GivenMatch) { + def cases(given ctx: Context): List[CaseDef] = internal.GivenMatch_cases(self) } given (given Context): IsInstanceOf[Try] = internal.isInstanceOfTry