Skip to content

Commit 2362c8f

Browse files
committed
Improve Matching.matched
1 parent 9219ec2 commit 2362c8f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ object Matcher {
201201
if patternHole.symbol.eq(defn.QuotedRuntimePatterns_patternHole) &&
202202
s.tpe <:< tpt.tpe &&
203203
tpt2.tpe.derivesFrom(defn.RepeatedParamClass) =>
204-
matched(quotes.reflect.TreeMethods.asExpr(scrutinee.asInstanceOf[quotes.reflect.Tree]))
204+
matched(scrutinee)
205205

206206
/* Term hole */
207207
// Match a scala.internal.Quoted.patternHole and return the scrutinee tree
208208
case (ClosedPatternTerm(scrutinee), TypeApply(patternHole, tpt :: Nil))
209209
if patternHole.symbol.eq(defn.QuotedRuntimePatterns_patternHole) &&
210210
scrutinee.tpe <:< tpt.tpe =>
211-
matched(quotes.reflect.TreeMethods.asExpr(scrutinee.asInstanceOf[quotes.reflect.Tree]))
211+
matched(scrutinee)
212212

213213
/* Higher order term hole */
214214
// Matches an open term and wraps it into a lambda that provides the free variables
@@ -235,8 +235,8 @@ object Matcher {
235235
ctx.owner,
236236
MethodType(names)(
237237
_ => argTypes, _ => resType),
238-
(meth, x) => TreeOps(bodyFn(x)).changeNonLocalOwners(meth.asInstanceOf))
239-
matched(quotes.reflect.TreeMethods.asExpr(res.asInstanceOf[quotes.reflect.Tree]))
238+
(meth, x) => TreeOps(bodyFn(x)).changeNonLocalOwners(meth))
239+
matched(res)
240240

241241
//
242242
// Match two equivalent trees
@@ -421,8 +421,11 @@ object Matcher {
421421
private object Matching {
422422

423423
def notMatched: Matching = None
424+
424425
val matched: Matching = Some(Tuple())
425-
def matched(x: Any): Matching = Some(Tuple1(x))
426+
427+
def matched(tree: Tree)(using Context): Matching =
428+
Some(Tuple1(new ExprImpl(tree, SpliceScope.getCurrent)))
426429

427430
extension (self: Matching)
428431
def asOptionOfTuple: Option[Tuple] = self

0 commit comments

Comments
 (0)