Skip to content

Commit a51e587

Browse files
committed
Implement extractors for TASTY trees
* Define TASTY data types in scala.tasty * Add method get a TASTY term from a quoted.Expr[T] * Implement TASTY tree extractors Use direct extractors for tasty trees Workaround issue #4449 Rename TopLevelStatement to Tree
1 parent 024a14f commit a51e587

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ object Splicer {
4848
*/
4949
private def getLiftedArgs(call: Tree, bindings: List[Tree])(implicit ctx: Context): List[Any] = {
5050
val bindMap = bindings.map {
51-
case vdef: ValOrDefDef => (vdef.rhs, ref(vdef.symbol).withPos(vdef.rhs.pos))
51+
case vdef: ValDef => (vdef.rhs, ref(vdef.symbol).withPos(vdef.rhs.pos))
52+
case ddef: DefDef => (ddef.rhs, ddef.rhs)
5253
}.toMap
5354
def allArgs(call: Tree, acc: List[List[Tree]]): List[List[Tree]] = call match {
5455
case call: Apply => allArgs(call.fun, call.args :: acc)

tests/pos/tasty/definitions.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,19 @@ object definitions {
3939
case class TypeDef(name: String, rhs: TypeTree | TypeBoundsTree) extends Definition {
4040
def mods: List[Modifier] = ???
4141
}
42-
case class ClassDef(name: String, constructor: DefDef, parents: List[Term | TypeTree],
42+
case class ClassDef(name: String, constructor: DefDef, parents: List[Parent],
4343
self: Option[ValDef], body: List[Statement]) extends Definition {
4444
def mods: List[Modifier] = ???
4545
}
4646
case class PackageDef(name: String, members: List[Statement]) extends Definition
4747

48+
// ------ Parents--------------------------------
49+
50+
enum Parent {
51+
case TermParent(parent: Term)
52+
case TypeParent(parent: TypeTree)
53+
}
54+
4855
// ------ Terms ---------------------------------
4956

5057
/** Trees denoting terms */

0 commit comments

Comments
 (0)