Skip to content

Commit 9729d35

Browse files
committed
Make QuoteMatcher to hold debug option
1 parent 9e379d1 commit 9729d35

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ import dotty.tools.dotc.util.optional
102102
*
103103
* ```
104104
*/
105-
object QuoteMatcher {
105+
class QuoteMatcher(private val debug: Boolean) {
106106
import tpd.*
107107

108108
/** Sequence of matched expressions.
@@ -131,7 +131,6 @@ object QuoteMatcher {
131131
given Env = Map.empty
132132
scrutinee =?= pat1
133133
}.map { matchings =>
134-
import QuoteMatcher.MatchResult.*
135134
lazy val spliceScope = SpliceScope.getCurrent
136135
// After matching and doing all subtype checks, we have to approximate all the type bindings
137136
// that we have found, seal them in a quoted.Type and add them to the result
@@ -462,7 +461,7 @@ object QuoteMatcher {
462461
notMatched
463462
end runMatch
464463

465-
if ctx.settings.YdebugMacros.value then
464+
if debug then
466465
try {
467466
runMatch()
468467
} catch {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ object QuotesImpl {
3939
class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler, QuoteMatching:
4040

4141
private val xCheckMacro: Boolean = ctx.settings.XcheckMacros.value
42+
private val quoteMatcher: QuoteMatcher = QuoteMatcher(ctx.settings.YdebugMacros.value)
4243

4344
extension [T](self: scala.quoted.Expr[T])
4445
def show: String =
4546
reflect.Printer.TreeCode.show(reflect.asTerm(self))
4647

4748
def matches(that: scala.quoted.Expr[Any]): Boolean =
48-
QuoteMatcher.treeMatch(reflect.asTerm(self), reflect.asTerm(that)).nonEmpty
49+
quoteMatcher.treeMatch(reflect.asTerm(self), reflect.asTerm(that)).nonEmpty
4950

5051
def valueOrAbort(using fromExpr: FromExpr[T]): T =
5152
def reportError =
@@ -3159,14 +3160,14 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
31593160
def unapply[TypeBindings, Tup <: Tuple](scrutinee: scala.quoted.Expr[Any])(using pattern: scala.quoted.Expr[Any]): Option[Tup] =
31603161
val scrutineeTree = reflect.asTerm(scrutinee)
31613162
val patternTree = reflect.asTerm(pattern)
3162-
QuoteMatcher.treeMatch(scrutineeTree, patternTree).asInstanceOf[Option[Tup]]
3163+
quoteMatcher.treeMatch(scrutineeTree, patternTree).asInstanceOf[Option[Tup]]
31633164
end ExprMatch
31643165

31653166
object TypeMatch extends TypeMatchModule:
31663167
def unapply[TypeBindings, Tup <: Tuple](scrutinee: scala.quoted.Type[?])(using pattern: scala.quoted.Type[?]): Option[Tup] =
31673168
val scrutineeTree = reflect.TypeTree.of(using scrutinee)
31683169
val patternTree = reflect.TypeTree.of(using pattern)
3169-
QuoteMatcher.treeMatch(scrutineeTree, patternTree).asInstanceOf[Option[Tup]]
3170+
quoteMatcher.treeMatch(scrutineeTree, patternTree).asInstanceOf[Option[Tup]]
31703171
end TypeMatch
31713172

31723173
end QuotesImpl

0 commit comments

Comments
 (0)