@@ -231,7 +231,7 @@ object Matcher {
231
231
scrutinee =?= expr2
232
232
233
233
/* Match selection */
234
- case (ref : Ref , Select (qual2, _)) if symbolMatch(scrutinee.symbol , pattern.symbol ) =>
234
+ case (ref : Ref , Select (qual2, _)) if symbolMatch(scrutinee, pattern) =>
235
235
ref match
236
236
case Select (qual1, _) => qual1 =?= qual2
237
237
case ref : Ident =>
@@ -240,7 +240,7 @@ object Matcher {
240
240
case _ => matched
241
241
242
242
/* Match reference */
243
- case (_ : Ref , _ : Ident ) if symbolMatch(scrutinee.symbol , pattern.symbol ) =>
243
+ case (_ : Ref , _ : Ident ) if symbolMatch(scrutinee, pattern) =>
244
244
matched
245
245
246
246
/* Match application */
@@ -348,10 +348,19 @@ object Matcher {
348
348
* - The scrutinee has is in the environment and they are equivalent
349
349
* - The scrutinee overrides the symbol of the pattern
350
350
*/
351
- private def symbolMatch (scrutinee : Symbol , pattern : Symbol )(using Env ): Boolean =
352
- scrutinee == pattern
353
- || summon[Env ].get(scrutinee).contains(pattern)
354
- || scrutinee.allOverriddenSymbols.contains(pattern)
351
+ private def symbolMatch (scrutineeTree : Tree , patternTree : Tree )(using Env ): Boolean =
352
+ val scrutinee = scrutineeTree.symbol
353
+ val devirtualizedScrutinee = scrutineeTree match
354
+ case Select (qual, _) =>
355
+ val sym = scrutinee.overridingSymbol(qual.tpe.typeSymbol)
356
+ if sym.exists then sym
357
+ else scrutinee
358
+ case _ => scrutinee
359
+ val pattern = patternTree.symbol
360
+
361
+ devirtualizedScrutinee == pattern
362
+ || summon[Env ].get(devirtualizedScrutinee).contains(pattern)
363
+ || devirtualizedScrutinee.allOverriddenSymbols.contains(pattern)
355
364
356
365
private object ClosedPatternTerm {
357
366
/** Matches a term that does not contain free variables defined in the pattern (i.e. not defined in `Env`) */
0 commit comments