Skip to content

Commit e2d5a8c

Browse files
committed
Use desugarIdent
1 parent fafab1a commit e2d5a8c

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
309309
def Ref_term(tp: TermRef)(using ctx: Context): Ref =
310310
withDefaultPos(tpd.ref(tp).asInstanceOf[tpd.RefTree])
311311

312+
def Ref_desugarIdent(tree: Ident)(using ctx: Context): Ref =
313+
tpd.desugarIdent(tree).asInstanceOf[tpd.RefTree]
314+
312315
def Ref_apply(sym: Symbol)(using ctx: Context): Ref = {
313316
assert(sym.isTerm)
314317
withDefaultPos(tpd.ref(sym).asInstanceOf[tpd.RefTree])

library/src/scala/internal/quoted/Matcher.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,12 @@ private[quoted] object Matcher {
272272
scrutinee =?= expr2
273273

274274
/* Match selection */
275-
case (ref: Ref, Select(qual2, _)) if scrutinee.symbol == pattern.symbol =>
276-
ref match
277-
case ref: Select => ref.qualifier =?= qual2
278-
case _ =>
279-
ref.tpe match
280-
case TermRef(qual: TermRef, _) => Ref.term(qual) =?= qual2
281-
case _ => matched
275+
case (Select(qual1, _), Select(qual2, _)) if scrutinee.symbol == pattern.symbol =>
276+
qual1 =?= qual2
277+
case (ref: Ident, Select(qual2, _)) if scrutinee.symbol == pattern.symbol =>
278+
Ref.desugarIdent(ref) match
279+
case Select(qual1, _) => qual1 =?= qual2
280+
case _ => matched
282281

283282
/* Match reference */
284283
case (_: Ref, _: Ident) if scrutinee.symbol == pattern.symbol || summon[Env].get(scrutinee.symbol).contains(pattern.symbol) =>

library/src/scala/tasty/Reflection.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,10 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
677677
def term(tp: TermRef)(using ctx: Context): Ref =
678678
internal.Ref_term(tp)
679679

680+
/** Desugar identifier into a select node. Return the tree itself if not possible */
681+
def desugarIdent(tree: Ident)(using ctx: Context): Ref =
682+
internal.Ref_desugarIdent(tree)
683+
680684
/** Create a reference tree from a symbol
681685
*
682686
* If `sym` refers to a class member `foo` in class `C`,

library/src/scala/tasty/reflect/CompilerInterface.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ trait CompilerInterface {
322322
/** A tree representing the same reference as the given type */
323323
def Ref_term(tp: TermRef)(using ctx: Context): Ref
324324

325+
/** Desugar identifier into a select node. Return the tree itself if not possible */
326+
def Ref_desugarIdent(tree: Ident)(using ctx: Context): Ref
327+
325328
def Ref_apply(sym: Symbol)(using ctx: Context): Ref
326329

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

0 commit comments

Comments
 (0)