File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed
compiler/src/dotty/tools/dotc/core
library/src/scala/internal/quoted Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -654,6 +654,9 @@ class Definitions {
654654 @ tu lazy val InternalQuotedExprModule : Symbol = ctx.requiredModule(" scala.internal.quoted.Expr" )
655655 @ tu lazy val InternalQuotedExpr_unapply : Symbol = InternalQuotedExprModule .requiredMethod(nme.unapply)
656656
657+ @ tu lazy val InternalQuotedTypeModule : Symbol = ctx.requiredModule(" scala.internal.quoted.Type" )
658+ @ tu lazy val InternalQuotedType_unapply : Symbol = InternalQuotedTypeModule .requiredMethod(nme.unapply)
659+
657660 @ tu lazy val QuotedTypeClass : ClassSymbol = ctx.requiredClass(" scala.quoted.Type" )
658661 @ tu lazy val QuotedType_splice : Symbol = QuotedTypeClass .requiredType(tpnme.splice)
659662
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ private[quoted] object Matcher {
4141 }
4242
4343 // TODO factor out common logic with `termMatch`
44- def typeTreeMatch (scrutineeTypeTree : Term , patternTypeTree : Term , hasTypeSplices : Boolean ): Option [Tuple ] = {
44+ def typeTreeMatch (scrutineeTypeTree : TypeTree , patternTypeTree : TypeTree , hasTypeSplices : Boolean ): Option [Tuple ] = {
4545 implicit val env : Env = Set .empty
4646 if (hasTypeSplices) {
4747 implicit val ctx : Context = internal.Context_GADT_setFreshGADTBounds (rootContext)
Original file line number Diff line number Diff line change 1+ package scala .internal .quoted
2+
3+ import scala .quoted ._
4+
5+ object Type {
6+
7+ /** Pattern matches an the scrutineeType against the patternType and returns a tuple
8+ * with the matched holes if successful.
9+ *
10+ * Holes:
11+ * - scala.internal.Quoted.patternHole[T]: hole that matches an expression `x` of type `Type[U]`
12+ * if `U <:< T` and returns `x` as part of the match.
13+ *
14+ * @param scrutineeType `Type[_]` on which we are pattern matching
15+ * @param patternType `Type[_]` containing the pattern tree
16+ * @param hasTypeSplices `Boolean` notify if the pattern has type splices (if so we use a GADT context)
17+ * @param qctx the current QuoteContext
18+ * @return None if it did not match, `Some(tup)` if it matched where `tup` contains `Type[Ti]``
19+ */
20+ def unapply [TypeBindings <: Tuple , Tup <: Tuple ](scrutineeType : Type [_])(implicit patternType : Type [_],
21+ hasTypeSplices : Boolean , qctx : QuoteContext ): Option [Tup ] = {
22+ import qctx .tasty ._
23+ new Matcher .QuoteMatcher [qctx.type ].typeTreeMatch(scrutineeType.unseal, patternType.unseal, hasTypeSplices).asInstanceOf [Option [Tup ]]
24+ }
25+
26+ }
You can’t perform that action at this time.
0 commit comments