Skip to content

Commit 7c776c7

Browse files
committed
Change Parent to TermOrTypeTree
1 parent 42de57a commit 7c776c7

File tree

10 files changed

+30
-30
lines changed

10 files changed

+30
-30
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/TastyCoreImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait TastyCoreImpl extends scala.tasty.reflect.TastyCore {
99

1010
type Context = core.Contexts.Context
1111

12-
type Parent = tpd.Tree
12+
type TermOrTypeTree = tpd.Tree
1313

1414
type Tree = tpd.Tree
1515
type PackageClause = tpd.PackageDef

compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with TastyCoreImpl with He
7171
}
7272

7373
object ClassDef extends ClassDefExtractor {
74-
def unapply(tree: Tree)(implicit ctx: Context): Option[(String, DefDef, List[Parent], Option[ValDef], List[Statement])] = tree match {
74+
def unapply(tree: Tree)(implicit ctx: Context): Option[(String, DefDef, List[TermOrTypeTree], Option[ValDef], List[Statement])] = tree match {
7575
case Trees.TypeDef(name, impl: tpd.Template) =>
7676
Some((name.toString, impl.constr, impl.parents, optional(impl.self), impl.body))
7777
case _ => None
@@ -193,8 +193,8 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with TastyCoreImpl with He
193193
object IsTerm extends IsTermExtractor {
194194
def unapply(tree: Tree)(implicit ctx: Context): Option[Term] =
195195
if (tree.isTerm) Some(tree) else None
196-
def unapply(parent: Parent)(implicit ctx: Context, dummy: DummyImplicit): Option[Term] =
197-
if (parent.isTerm) Some(parent) else None
196+
def unapply(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[Term] =
197+
if (termOrTypeTree.isTerm) Some(termOrTypeTree) else None
198198
}
199199

200200
object Term extends TermModule {
@@ -316,7 +316,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with TastyCoreImpl with He
316316
}
317317

318318
object Inlined extends InlinedExtractor {
319-
def unapply(x: Term)(implicit ctx: Context): Option[(Option[Parent], List[Statement], Term)] = x match {
319+
def unapply(x: Term)(implicit ctx: Context): Option[(Option[TermOrTypeTree], List[Statement], Term)] = x match {
320320
case x: tpd.Inlined =>
321321
Some((optional(x.call), x.bindings, x.expansion))
322322
case _ => None
@@ -384,5 +384,5 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with TastyCoreImpl with He
384384
}
385385
}
386386

387-
def termAsParent(term: Term): Parent = term
387+
def termAsTermOrTypeTree(term: Term): TermOrTypeTree = term
388388
}

compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
2525
object IsTypeTree extends IsTypeTreeExtractor {
2626
def unapply(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree] =
2727
if (x.isType) Some(x) else None
28-
def unapply(x: Parent)(implicit ctx: Context, dummy: DummyImplicit): Option[TypeTree] =
29-
if (x.isType) Some(x) else None
28+
def unapply(termOrTypeTree: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[TypeTree] =
29+
if (termOrTypeTree.isType) Some(termOrTypeTree) else None
3030
}
3131

3232
object TypeTree extends TypeTreeModule {
@@ -153,5 +153,5 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
153153
}
154154
}
155155

156-
def typeTreeAsParent(typeTree: TypeTree): Parent = typeTree
156+
def typeTreeAsParent(typeTree: TypeTree): TermOrTypeTree = typeTree
157157
}

library/src/scala/tasty/reflect/TastyCore.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ package scala.tasty.reflect
9999
* +- Symbol
100100
*
101101
* Aliases:
102-
* # Parent = Term | TypeTree
102+
* # TermOrTypeTree = Term | TypeTree
103103
*
104104
* ```
105105
*/
@@ -110,7 +110,7 @@ trait TastyCore {
110110

111111
// TODO: When bootstrapped, remove and use `Term | TypeTree` type directly in other files
112112
/** Workaround missing `|` types in Scala 2 to represent `Term | TypeTree` */
113-
type Parent /* Term | TypeTree */
113+
type TermOrTypeTree /* Term | TypeTree */
114114

115115
/** Tree representing executable code written in the source */
116116
type Tree

library/src/scala/tasty/reflect/TreeOps.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ trait TreeOps extends TastyCore {
5858

5959
val ClassDef: ClassDefExtractor
6060
abstract class ClassDefExtractor {
61-
def unapply(tree: Tree)(implicit ctx: Context): Option[(String, DefDef, List[Parent], Option[ValDef], List[Statement])]
61+
def unapply(tree: Tree)(implicit ctx: Context): Option[(String, DefDef, List[TermOrTypeTree], Option[ValDef], List[Statement])]
6262
}
6363

6464
trait ClassDefAPI {
6565
def constructor(implicit ctx: Context): DefDef
66-
def parents(implicit ctx: Context): List[Parent]
66+
def parents(implicit ctx: Context): List[TermOrTypeTree]
6767
def self(implicit ctx: Context): Option[ValDef]
6868
def body(implicit ctx: Context): List[Statement]
6969
}
@@ -156,7 +156,7 @@ trait TreeOps extends TastyCore {
156156
/** Matches any term */
157157
def unapply(tree: Tree)(implicit ctx: Context): Option[Term]
158158
/** Matches any term */
159-
def unapply(parent: Parent)(implicit ctx: Context, dummy: DummyImplicit): Option[Term]
159+
def unapply(parent: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[Term]
160160
}
161161

162162
/** Scala term. Any tree that can go in expression position. */
@@ -286,7 +286,7 @@ trait TreeOps extends TastyCore {
286286

287287
val Inlined: InlinedExtractor
288288
abstract class InlinedExtractor {
289-
def unapply(tree: Tree)(implicit ctx: Context): Option[(Option[Parent], List[Definition], Term)]
289+
def unapply(tree: Tree)(implicit ctx: Context): Option[(Option[TermOrTypeTree], List[Definition], Term)]
290290
}
291291

292292
val SelectOuter: SelectOuterExtractor
@@ -301,5 +301,5 @@ trait TreeOps extends TastyCore {
301301
}
302302
}
303303

304-
implicit def termAsParent(term: Term): Parent
304+
implicit def termAsTermOrTypeTree(term: Term): TermOrTypeTree
305305
}

library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ trait TypeOrBoundsTreeOps extends TastyCore {
1919
val IsTypeTree: IsTypeTreeExtractor
2020
abstract class IsTypeTreeExtractor {
2121
def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeTree]
22-
def unapply(parent: Parent)(implicit ctx: Context, dummy: DummyImplicit): Option[TypeTree]
22+
def unapply(parent: TermOrTypeTree)(implicit ctx: Context, dummy: DummyImplicit): Option[TypeTree]
2323
}
2424

2525
val TypeTree: TypeTreeModule
@@ -119,5 +119,5 @@ trait TypeOrBoundsTreeOps extends TastyCore {
119119
def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Boolean
120120
}
121121

122-
implicit def typeTreeAsParent(term: TypeTree): Parent
122+
implicit def typeTreeAsParent(term: TypeTree): TermOrTypeTree
123123
}

library/src/scala/tasty/util/ShowExtractors.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
7070
this += "Term.Repeated(" ++= elems += ")"
7171
case Term.Inlined(call, bindings, expansion) =>
7272
this += "Term.Inlined("
73-
visitOption(call, visitParent)
73+
visitOption(call, visitTermOrTypeTree)
7474
this += ", " ++= bindings += ", " += expansion += ")"
7575
case ValDef(name, tpt, rhs) =>
7676
this += "ValDef(\"" += name += "\", " += tpt += ", " += rhs += ")"
@@ -80,7 +80,7 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
8080
this += "TypeDef(\"" += name += "\", " += rhs += ")"
8181
case ClassDef(name, constr, parents, self, body) =>
8282
this += "ClassDef(\"" += name += "\", " += constr += ", "
83-
visitList[Parent](parents, visitParent)
83+
visitList[TermOrTypeTree](parents, visitTermOrTypeTree)
8484
this += ", " += self += ", " ++= body += ")"
8585
case PackageDef(name, owner) =>
8686
this += "PackageDef(\"" += name += "\", " += owner += ")"
@@ -141,9 +141,9 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
141141
this += "Pattern.TypeTest(" += tpt += ")"
142142
}
143143

144-
def visitParent(x: Parent): Buffer = x match {
145-
case IsTerm(parent) => this += parent
146-
case IsTypeTree(parent) => this += parent
144+
def visitTermOrTypeTree(x: TermOrTypeTree): Buffer = x match {
145+
case IsTerm(termOrTypeTree) => this += termOrTypeTree
146+
case IsTypeTree(termOrTypeTree) => this += termOrTypeTree
147147
}
148148

149149
def visitConstant(x: Constant): Buffer = x match {

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
122122
if (parents1.nonEmpty)
123123
this += " extends "
124124

125-
def printParent(parent: Parent): Unit = parent match {
125+
def printParent(parent: TermOrTypeTree): Unit = parent match {
126126
case IsTypeTree(parent) =>
127127
printTypeTree(parent)
128128
case IsTerm(Term.TypeApply(fun, targs)) =>
@@ -137,7 +137,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
137137
throw new MatchError(parent.show)
138138
}
139139

140-
def printSeparated(list: List[Parent]): Unit = list match {
140+
def printSeparated(list: List[TermOrTypeTree]): Unit = list match {
141141
case Nil =>
142142
case x :: Nil => printParent(x)
143143
case x :: xs =>

library/src/scala/tasty/util/TreeAccumulator.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ abstract class TreeAccumulator[X, T <: Tasty with Singleton](val tasty: T) {
1515
def foldTypeTrees(x: X, trees: Iterable[TypeOrBoundsTree])(implicit ctx: Context): X = (x /: trees)(foldTypeTree)
1616
def foldCaseDefs(x: X, trees: Iterable[CaseDef])(implicit ctx: Context): X = (x /: trees)(foldCaseDef)
1717
def foldPatterns(x: X, trees: Iterable[Pattern])(implicit ctx: Context): X = (x /: trees)(foldPattern)
18-
private def foldParents(x: X, trees: Iterable[Parent])(implicit ctx: Context): X = (x /: trees)(foldOverParent)
18+
private def foldParents(x: X, trees: Iterable[TermOrTypeTree])(implicit ctx: Context): X = (x /: trees)(foldOverTermOrTypeTree)
1919

2020
def foldOverTree(x: X, tree: Tree)(implicit ctx: Context): X = {
2121
def localCtx(definition: Definition): Context = definition.symbol.localContext
@@ -105,9 +105,9 @@ abstract class TreeAccumulator[X, T <: Tasty with Singleton](val tasty: T) {
105105
case Pattern.TypeTest(tpt) => foldTypeTree(x, tpt)
106106
}
107107

108-
private def foldOverParent(x: X, tree: Parent)(implicit ctx: Context): X = tree match {
109-
case IsTerm(tree) => foldOverTree(x, tree)
110-
case IsTypeTree(tree) => foldOverTypeTree(x, tree)
108+
private def foldOverTermOrTypeTree(x: X, tree: TermOrTypeTree)(implicit ctx: Context): X = tree match {
109+
case IsTerm(termOrTypeTree) => foldOverTree(x, termOrTypeTree)
110+
case IsTypeTree(termOrTypeTree) => foldOverTypeTree(x, termOrTypeTree)
111111
}
112112

113113
}

tests/pos-special/fatal-warnings/tasty-parent-unapply.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object Macros {
88
def impl(tasty: Tasty): Unit = {
99
import tasty._
1010

11-
def foo(tree: Tree, term: Term, typeTree: TypeTree, parent: Parent) = {
11+
def foo(tree: Tree, term: Term, typeTree: TypeTree, parent: TermOrTypeTree) = {
1212

1313
tree match {
1414
case IsTerm(tree) =>

0 commit comments

Comments
 (0)