diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala index a4f891a0b641..be059ded4748 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala @@ -5,8 +5,6 @@ import dotty.tools.dotc.core import dotty.tools.dotc.core.Decorators._ import dotty.tools.dotc.core.StdNames.nme import dotty.tools.dotc.core._ -import dotty.tools.dotc.reporting.Reporter -import dotty.tools.dotc.reporting.diagnostic.MessageContainer import dotty.tools.dotc.tastyreflect.FromSymbol.{definitionFromSym, packageDefFromSym} trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with TastyCoreImpl with Helpers { @@ -399,4 +397,5 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with TastyCoreImpl with He } } + def termAsParent(term: Term): Parent = term } diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala index c6189eaf606d..6391640e37d3 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala @@ -153,4 +153,5 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w } } + def typeTreeAsParent(typeTree: TypeTree): Parent = typeTree } diff --git a/library/src/scala/tasty/reflect/TastyCore.scala b/library/src/scala/tasty/reflect/TastyCore.scala index 27391693506b..8f6e7eea1289 100644 --- a/library/src/scala/tasty/reflect/TastyCore.scala +++ b/library/src/scala/tasty/reflect/TastyCore.scala @@ -13,29 +13,29 @@ package scala.tasty.reflect * | +- PackageDef * | * +- Term --------+- Ident - * / +- Select - * / +- Literal - * / +- This - * / +- New - * / +- NamedArg - * / +- Apply - * / +- TypeApply - * / +- Super - * / +- Typed - * / +- Assign - * / +- Block - * +- Parent ----+ +- Lambda - * \ +- If - * \ +- Match - * \ +- Try - * \ +- Return - * \ +- Repeated - * \ +- Inlined - * \ +- SelectOuter - * \ +- While - * \ +- DoWhile - * \ - * \ + * +- Select + * +- Literal + * +- This + * +- New + * +- NamedArg + * +- Apply + * +- TypeApply + * +- Super + * +- Typed + * +- Assign + * +- Block + * +- Lambda + * +- If + * +- Match + * +- Try + * +- Return + * +- Repeated + * +- Inlined + * +- SelectOuter + * +- While + * +- DoWhile + * + * * +- TypeTree ----+- Synthetic * | +- TypeIdent * | +- TermSelect @@ -98,6 +98,9 @@ package scala.tasty.reflect * * +- Symbol * + * Aliases: + * # Parent = Term | TypeTree + * * ``` */ trait TastyCore { @@ -120,7 +123,7 @@ trait TastyCore { type DefDef <: Definition type ValDef <: Definition type PackageDef <: Definition - type Term <: Statement with Parent // TODO: When bootstrapped, remove `Parent` + type Term <: Statement /** Branch of a pattern match or catch clause */ type CaseDef @@ -130,7 +133,7 @@ trait TastyCore { /** Tree representing a type written in the source */ type TypeOrBoundsTree - type TypeTree <: TypeOrBoundsTree with Parent // TODO: When bootstrapped, remove `Parent` + type TypeTree <: TypeOrBoundsTree type TypeBoundsTree <: TypeOrBoundsTree type TypeOrBounds diff --git a/library/src/scala/tasty/reflect/TreeOps.scala b/library/src/scala/tasty/reflect/TreeOps.scala index d66f309ca47d..f084120f6dd8 100644 --- a/library/src/scala/tasty/reflect/TreeOps.scala +++ b/library/src/scala/tasty/reflect/TreeOps.scala @@ -306,4 +306,5 @@ trait TreeOps extends TastyCore { } } + implicit def termAsParent(term: Term): Parent } diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala index b23aa7623e77..13f76e72e16a 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala @@ -119,4 +119,5 @@ trait TypeOrBoundsTreeOps extends TastyCore { def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Boolean } + implicit def typeTreeAsParent(term: TypeTree): Parent } diff --git a/tests/pos-special/fatal-warnings/tasty-parent-unapply.scala b/tests/pos-special/fatal-warnings/tasty-parent-unapply.scala new file mode 100644 index 000000000000..07fd102b01ee --- /dev/null +++ b/tests/pos-special/fatal-warnings/tasty-parent-unapply.scala @@ -0,0 +1,33 @@ +import scala.quoted._ + +import scala.tasty.Tasty + +object Macros { + + + def impl(tasty: Tasty): Unit = { + import tasty._ + + def foo(tree: Tree, term: Term, typeTree: TypeTree, parent: Parent) = { + + tree match { + case IsTerm(tree) => + } + + term match { + case IsTerm(term) => + } + + typeTree match { + case IsTypeTree(typeTree) => + } + + parent match { + case IsTerm(typeTree) => + case IsTypeTree(typeTree) => + } + + } + } + +}