Skip to content

Commit 77208d3

Browse files
committed
Port symbolMatch
1 parent 02b3896 commit 77208d3

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

compiler/src/scala/quoted/runtime/impl/Matcher.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ object Matcher {
232232
scrutinee =?= expr2
233233

234234
/* Match selection */
235-
case (ref: Ref, Select(qual2, _)) if symbolMatch(scrutinee, pattern) =>
235+
case (ref: Ref, Select(qual2, _)) if symbolMatch(scrutinee.asInstanceOf, pattern.asInstanceOf) =>
236236
ref match
237237
case Select(qual1, _) => qual1 =?= qual2
238238
case ref: Ident =>
@@ -241,7 +241,7 @@ object Matcher {
241241
case _ => matched
242242

243243
/* Match reference */
244-
case (_: Ref, _: Ident) if symbolMatch(scrutinee, pattern) =>
244+
case (_: Ref, _: Ident) if symbolMatch(scrutinee.asInstanceOf, pattern.asInstanceOf) =>
245245
matched
246246

247247
/* Match application */
@@ -360,18 +360,25 @@ object Matcher {
360360
* - The scrutinee has is in the environment and they are equivalent
361361
* - The scrutinee overrides the symbol of the pattern
362362
*/
363-
private def symbolMatch(scrutineeTree: Tree, patternTree: Tree)(using Env): Boolean =
363+
private def symbolMatch(scrutineeTree: dotc.ast.tpd.Tree, patternTree: dotc.ast.tpd.Tree)(using Env): Boolean =
364+
import dotc.ast.tpd.* // TODO remove
364365
val scrutinee = scrutineeTree.symbol
366+
367+
def overridingSymbol(ofclazz: dotc.core.Symbols.Symbol): dotc.core.Symbols.Symbol =
368+
if ofclazz.isClass then scrutinee.denot.overridingSymbol(ofclazz.asClass)
369+
else dotc.core.Symbols.NoSymbol
370+
365371
val devirtualizedScrutinee = scrutineeTree match
366372
case Select(qual, _) =>
367-
val sym = scrutinee.overridingSymbol(qual.tpe.typeSymbol)
373+
val sym = overridingSymbol(qual.tpe.typeSymbol)
368374
if sym.exists then sym
369375
else scrutinee
370376
case _ => scrutinee
371377
val pattern = patternTree.symbol
372378

379+
373380
devirtualizedScrutinee == pattern
374-
|| summon[Env].get(devirtualizedScrutinee).contains(pattern)
381+
|| summon[Env].get(devirtualizedScrutinee.asInstanceOf).contains(pattern)
375382
|| devirtualizedScrutinee.allOverriddenSymbols.contains(pattern)
376383

377384
private object ClosedPatternTerm {

0 commit comments

Comments
 (0)