Skip to content

Commit 37eacd9

Browse files
Merge pull request #4998 from dotty-staging/fix-parents-tasty-reflect
Fix ambiguous unapply for TASTy reflect Parent
2 parents 724376e + 12f0e43 commit 37eacd9

File tree

6 files changed

+65
-27
lines changed

6 files changed

+65
-27
lines changed

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import dotty.tools.dotc.core
55
import dotty.tools.dotc.core.Decorators._
66
import dotty.tools.dotc.core.StdNames.nme
77
import dotty.tools.dotc.core._
8-
import dotty.tools.dotc.reporting.Reporter
9-
import dotty.tools.dotc.reporting.diagnostic.MessageContainer
108
import dotty.tools.dotc.tastyreflect.FromSymbol.{definitionFromSym, packageDefFromSym}
119

1210
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
399397
}
400398
}
401399

400+
def termAsParent(term: Term): Parent = term
402401
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,5 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
153153
}
154154
}
155155

156+
def typeTreeAsParent(typeTree: TypeTree): Parent = typeTree
156157
}

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

+28-25
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,29 @@ package scala.tasty.reflect
1313
* | +- PackageDef
1414
* |
1515
* +- Term --------+- Ident
16-
* / +- Select
17-
* / +- Literal
18-
* / +- This
19-
* / +- New
20-
* / +- NamedArg
21-
* / +- Apply
22-
* / +- TypeApply
23-
* / +- Super
24-
* / +- Typed
25-
* / +- Assign
26-
* / +- Block
27-
* +- Parent ----+ +- Lambda
28-
* \ +- If
29-
* \ +- Match
30-
* \ +- Try
31-
* \ +- Return
32-
* \ +- Repeated
33-
* \ +- Inlined
34-
* \ +- SelectOuter
35-
* \ +- While
36-
* \ +- DoWhile
37-
* \
38-
* \
16+
* +- Select
17+
* +- Literal
18+
* +- This
19+
* +- New
20+
* +- NamedArg
21+
* +- Apply
22+
* +- TypeApply
23+
* +- Super
24+
* +- Typed
25+
* +- Assign
26+
* +- Block
27+
* +- Lambda
28+
* +- If
29+
* +- Match
30+
* +- Try
31+
* +- Return
32+
* +- Repeated
33+
* +- Inlined
34+
* +- SelectOuter
35+
* +- While
36+
* +- DoWhile
37+
*
38+
*
3939
* +- TypeTree ----+- Synthetic
4040
* | +- TypeIdent
4141
* | +- TermSelect
@@ -98,6 +98,9 @@ package scala.tasty.reflect
9898
*
9999
* +- Symbol
100100
*
101+
* Aliases:
102+
* # Parent = Term | TypeTree
103+
*
101104
* ```
102105
*/
103106
trait TastyCore {
@@ -120,7 +123,7 @@ trait TastyCore {
120123
type DefDef <: Definition
121124
type ValDef <: Definition
122125
type PackageDef <: Definition
123-
type Term <: Statement with Parent // TODO: When bootstrapped, remove `Parent`
126+
type Term <: Statement
124127

125128
/** Branch of a pattern match or catch clause */
126129
type CaseDef
@@ -130,7 +133,7 @@ trait TastyCore {
130133

131134
/** Tree representing a type written in the source */
132135
type TypeOrBoundsTree
133-
type TypeTree <: TypeOrBoundsTree with Parent // TODO: When bootstrapped, remove `Parent`
136+
type TypeTree <: TypeOrBoundsTree
134137
type TypeBoundsTree <: TypeOrBoundsTree
135138

136139
type TypeOrBounds

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

+1
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,5 @@ trait TreeOps extends TastyCore {
306306
}
307307
}
308308

309+
implicit def termAsParent(term: Term): Parent
309310
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,5 @@ trait TypeOrBoundsTreeOps extends TastyCore {
119119
def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Boolean
120120
}
121121

122+
implicit def typeTreeAsParent(term: TypeTree): Parent
122123
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import scala.quoted._
2+
3+
import scala.tasty.Tasty
4+
5+
object Macros {
6+
7+
8+
def impl(tasty: Tasty): Unit = {
9+
import tasty._
10+
11+
def foo(tree: Tree, term: Term, typeTree: TypeTree, parent: Parent) = {
12+
13+
tree match {
14+
case IsTerm(tree) =>
15+
}
16+
17+
term match {
18+
case IsTerm(term) =>
19+
}
20+
21+
typeTree match {
22+
case IsTypeTree(typeTree) =>
23+
}
24+
25+
parent match {
26+
case IsTerm(typeTree) =>
27+
case IsTypeTree(typeTree) =>
28+
}
29+
30+
}
31+
}
32+
33+
}

0 commit comments

Comments
 (0)