Skip to content

Commit 3663724

Browse files
committed
wip
1 parent 5073cce commit 3663724

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,16 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
7878

7979
type Definition = tpd.Tree
8080

81-
def isDefinition (tree: Tree)(implicit ctx: Context): Option[Definition] = tree match {
81+
def isDefinition(tree: Tree)(implicit ctx: Context): Option[Definition] = tree match {
8282
case tree: tpd.MemberDef => Some(tree)
8383
case tree: PackageDefinition => Some(tree)
8484
case _ => None
8585
}
8686

87-
def Definition_name(self: Definition)(implicit ctx: Context): String = self.symbol.name.toString
87+
def Definition_name(self: Definition)(implicit ctx: Context): String = self match {
88+
case self: tpd.MemberDef => self.name.toString
89+
case self: PackageDefinition => self.symbol.name.toString // TODO make PackageDefinition a MemberDef or NameTree
90+
}
8891

8992
type PackageDef = PackageDefinition
9093

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with RootPositionImpl with
6060

6161
def copy(original: ValDef)(name: String, tpt: TypeTree, rhs: Option[Term])(implicit ctx: Context): ValDef =
6262
tpd.cpy.ValDef(original)(name.toTermName, tpt, rhs.getOrElse(tpd.EmptyTree))
63-
64-
def unapply(tree: Tree)(implicit ctx: Context): Option[(String, TypeTree, Option[Term])] = tree match {
65-
case x: tpd.ValDef =>
66-
Some((x.name.toString, x.tpt, optional(x.rhs)))
67-
case _ => None
68-
}
6963
}
7064

7165

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ trait TreeOps extends Core {
124124
abstract class ValDefModule {
125125
def apply(sym: ValSymbol, rhs: Option[Term])(implicit ctx: Context): ValDef
126126
def copy(original: ValDef)(name: String, tpt: TypeTree, rhs: Option[Term])(implicit ctx: Context): ValDef
127-
def unapply(tree: Tree)(implicit ctx: Context): Option[(String, TypeTree, Option[Term])]
127+
def unapply(tree: Tree)(implicit ctx: Context): Option[(String, TypeTree, Option[Term])] =
128+
kernel.isValDef(tree).map(x => (x.name, x.tpt, x.rhs))
128129
}
129130

130131
implicit class ValDefAPI(self: ValDef) {

0 commit comments

Comments
 (0)