@@ -103,14 +103,13 @@ import dotty.tools.dotc.core.StdNames.nme
103
103
object Matcher {
104
104
import tpd .*
105
105
106
- class QuoteMatcher [ QCtx <: Quotes & Singleton ] (val qctx : QCtx )(using Context ) {
106
+ class QuoteMatcher (val quotes : Quotes )(using Context ) {
107
107
108
108
// TODO improve performance
109
109
110
- // TODO use flag from qctx.reflect . Maybe -debug or add -debug-macros
110
+ // TODO use flag from Context . Maybe -debug or add -debug-macros
111
111
private inline val debug = false
112
112
113
- import qctx .reflect ._
114
113
import Matching ._
115
114
116
115
/** A map relating equivalent symbols from the scrutinee and the pattern
@@ -124,11 +123,11 @@ object Matcher {
124
123
125
124
inline private def withEnv [T ](env : Env )(inline body : Env ?=> T ): T = body(using env)
126
125
127
- def termMatch (scrutineeTerm : Term , patternTerm : Term ): Option [Tuple ] =
126
+ def termMatch (scrutineeTerm : tpd. Tree , patternTerm : tpd. Tree ): Option [Tuple ] =
128
127
given Env = Map .empty
129
128
scrutineeTerm =?= patternTerm
130
129
131
- def typeTreeMatch (scrutineeTypeTree : TypeTree , patternTypeTree : TypeTree ): Option [Tuple ] =
130
+ def typeTreeMatch (scrutineeTypeTree : tpd. Tree , patternTypeTree : tpd. Tree ): Option [Tuple ] =
132
131
given Env = Map .empty
133
132
scrutineeTypeTree =?= patternTypeTree
134
133
@@ -139,9 +138,6 @@ object Matcher {
139
138
case _ => notMatched
140
139
}
141
140
142
- extension (scrutinee : Tree )
143
- private def =?= (pattern : Tree )(using Env ): Matching =
144
- scrutinee.asInstanceOf [tpd.Tree ] =?= pattern.asInstanceOf [tpd.Tree ]
145
141
extension (scrutinees : List [tpd.Tree ])
146
142
private def =?= (patterns : List [tpd.Tree ])(using Env )(using DummyImplicit ): Matching =
147
143
matchLists(scrutinees, patterns)(_ =?= _)
@@ -206,14 +202,14 @@ object Matcher {
206
202
if patternHole.symbol.eq(dotc.core.Symbols .defn.QuotedRuntimePatterns_patternHole ) &&
207
203
s.tpe <:< tpt.tpe &&
208
204
tpt2.tpe.derivesFrom(defn.RepeatedParamClass ) =>
209
- matched(qctx .reflect.TreeMethods .asExpr(scrutinee.asInstanceOf [qctx .reflect.Tree ]))
205
+ matched(quotes .reflect.TreeMethods .asExpr(scrutinee.asInstanceOf [quotes .reflect.Tree ]))
210
206
211
207
/* Term hole */
212
208
// Match a scala.internal.Quoted.patternHole and return the scrutinee tree
213
209
case (ClosedPatternTerm (scrutinee), TypeApply (patternHole, tpt :: Nil ))
214
210
if patternHole.symbol.eq(dotc.core.Symbols .defn.QuotedRuntimePatterns_patternHole ) &&
215
211
scrutinee.tpe <:< tpt.tpe =>
216
- matched(qctx .reflect.TreeMethods .asExpr(scrutinee.asInstanceOf [qctx .reflect.Tree ]))
212
+ matched(quotes .reflect.TreeMethods .asExpr(scrutinee.asInstanceOf [quotes .reflect.Tree ]))
217
213
218
214
/* Higher order term hole */
219
215
// Matches an open term and wraps it into a lambda that provides the free variables
@@ -241,7 +237,7 @@ object Matcher {
241
237
MethodType (names)(
242
238
_ => argTypes, _ => resType),
243
239
(meth, x) => tpd.TreeOps (bodyFn(x)).changeNonLocalOwners(meth.asInstanceOf ))
244
- matched(qctx .reflect.TreeMethods .asExpr(res.asInstanceOf [qctx .reflect.Tree ]))
240
+ matched(quotes .reflect.TreeMethods .asExpr(res.asInstanceOf [quotes .reflect.Tree ]))
245
241
246
242
//
247
243
// Match two equivalent trees
@@ -369,8 +365,8 @@ object Matcher {
369
365
|
370
366
|with environment: ${summon[Env ]}
371
367
|
372
- |Scrutinee: ${Printer .TreeStructure .show(scrutinee.asInstanceOf )}
373
- |Pattern: ${Printer .TreeStructure .show(pattern.asInstanceOf )}
368
+ |Scrutinee: ${quotes.reflect. Printer .TreeStructure .show(scrutinee.asInstanceOf )}
369
+ |Pattern: ${quotes.reflect. Printer .TreeStructure .show(pattern.asInstanceOf )}
374
370
|
375
371
| """ .stripMargin)
376
372
notMatched
0 commit comments