Skip to content

Commit ea3ecf6

Browse files
committed
Use Ref trees
1 parent 1db26d5 commit ea3ecf6

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
239239

240240
type Ref = tpd.RefTree
241241

242+
def matchRef(tree: Tree)(implicit ctx: Context): Option[Ref] = tree match {
243+
case x: tpd.RefTree if x.isTerm => Some(x)
244+
case _ => None
245+
}
246+
242247
def Ref_apply(sym: Symbol)(implicit ctx: Context): Ref =
243248
withDefaultPos(ctx => tpd.ref(sym)(ctx).asInstanceOf[tpd.RefTree])
244249

library/src-bootstrapped/scala/runtime/quoted/Matcher.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,16 @@ object Matcher {
7676
case (Literal(constant1), Literal(constant2)) if constant1 == constant2 =>
7777
Some(())
7878

79-
case (Ident(_), Ident(_)) if scrutinee.symbol == pattern.symbol || env((scrutinee.symbol, pattern.symbol)) =>
80-
Some(())
81-
8279
case (Typed(expr1, tpt1), Typed(expr2, tpt2)) =>
8380
foldMatchings(treeMatches(expr1, expr2), treeMatches(tpt1, tpt2))
8481

82+
case (Ident(_), Ident(_)) if scrutinee.symbol == pattern.symbol || env((scrutinee.symbol, pattern.symbol)) =>
83+
Some(())
84+
8585
case (Select(qual1, _), Select(qual2, _)) if scrutinee.symbol == pattern.symbol =>
8686
treeMatches(qual1, qual2)
8787

88-
case (Ident(_), Select(_, _)) if scrutinee.symbol == pattern.symbol =>
89-
Some(())
90-
91-
case (Select(_, _), Ident(_)) if scrutinee.symbol == pattern.symbol =>
88+
case (IsRef(_), IsRef(_, _)) if scrutinee.symbol == pattern.symbol =>
9289
Some(())
9390

9491
case (Apply(fn1, args1), Apply(fn2, args2)) if fn1.symbol == fn2.symbol =>

library/src/scala/tasty/reflect/Kernel.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ trait Kernel {
295295
/** Tree representing a reference to definition */
296296
type Ref <: Term
297297

298+
def matchRef(tree: Tree)(implicit ctx: Context): Option[Ref]
299+
298300
def Ref_apply(sym: Symbol)(implicit ctx: Context): Ref
299301

300302
/** Tree representing a reference to definition with a given name */

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ trait TreeOps extends Core {
187187
kernel.matchTerm(tree)
188188
}
189189

190+
object IsRef {
191+
/** Matches any Ref and returns it */
192+
def unapply(tree: Tree)(implicit ctx: Context): Option[Ref] = kernel.matchRef(tree)
193+
}
194+
190195
object Ref {
191196

192197
/** Create a reference tree */

0 commit comments

Comments
 (0)