@@ -101,7 +101,7 @@ object Matcher {
101101 // TODO improve performance
102102
103103 // TODO use flag from qctx.reflect. Maybe -debug or add -debug-macros
104- private final val debug = false
104+ private inline val debug = false
105105
106106 import qctx .reflect ._
107107 import Matching ._
@@ -231,7 +231,7 @@ object Matcher {
231231 scrutinee =?= expr2
232232
233233 /* Match selection */
234- case (ref : Ref , Select (qual2, _)) if scrutinee.symbol == pattern.symbol || summon[ Env ].get (scrutinee.symbol).contains( pattern.symbol) =>
234+ case (ref : Ref , Select (qual2, _)) if symbolMatch (scrutinee.symbol, pattern.symbol) =>
235235 ref match
236236 case Select (qual1, _) => qual1 =?= qual2
237237 case ref : Ident =>
@@ -240,7 +240,7 @@ object Matcher {
240240 case _ => matched
241241
242242 /* Match reference */
243- case (_ : Ref , _ : Ident ) if scrutinee.symbol == pattern.symbol || summon[ Env ].get (scrutinee.symbol).contains( pattern.symbol) =>
243+ case (_ : Ref , _ : Ident ) if symbolMatch (scrutinee.symbol, pattern.symbol) =>
244244 matched
245245
246246 /* Match application */
@@ -329,23 +329,30 @@ object Matcher {
329329 s """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
330330 |Scrutinee
331331 | ${scrutinee.show}
332- |
333- | ${scrutinee.showExtractors}
334- |
335332 |did not match pattern
336333 | ${pattern.show}
337334 |
338- | ${pattern.showExtractors}
339- |
340335 |with environment: ${summon[Env ]}
341336 |
337+ |Scrutinee: ${scrutinee.showExtractors}
338+ |Pattern: ${pattern.showExtractors}
342339 |
343340 | """ .stripMargin)
344341 notMatched
345342 }
346343 }
347344 end extension
348345
346+ /** Does the scrutenne symbol match the pattern symbol? It matches if:
347+ * - They are the same symbol
348+ * - The scrutinee has is in the environment and they are equivalent
349+ * - The scrutinee overrides the symbol of the pattern
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)
355+
349356 private object ClosedPatternTerm {
350357 /** Matches a term that does not contain free variables defined in the pattern (i.e. not defined in `Env`) */
351358 def unapply (term : Term )(using Env ): Option [term.type ] =
0 commit comments