Skip to content

Commit f032a19

Browse files
committed
Add scala.internal.quoted.Type.unapply
1 parent 33ca2cd commit f032a19

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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

library/src/scala/internal/quoted/Matcher.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

0 commit comments

Comments
 (0)