Skip to content

Commit eada469

Browse files
committed
Fix UnapplyTypeTest
1 parent 4732288 commit eada469

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

compiler/src/scala/quoted/internal/impl/QuoteContextImpl.scala

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,13 +1429,14 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, QuoteUnpickl
14291429
end extension
14301430
end BindMethodsImpl
14311431

1432-
type Unapply = tpd.UnApply
1432+
type Unapply = tpd.UnApply | tpd.Typed // tpd.Typed containing a tpd.UnApply as expression
14331433

14341434
object UnapplyTypeTest extends TypeTest[Tree, Unapply]:
1435-
def unapply(x: Tree): Option[Unapply & x.type] = x match
1436-
case x: (tpd.UnApply & x.type) => Some(x)
1437-
case dotc.ast.Trees.Typed(pattern: tpd.UnApply, _) => Some(pattern.asInstanceOf[Unapply & x.type]) // FIXME return x
1438-
case _ => None
1435+
def unapply(x: Tree): Option[Unapply & x.type] =
1436+
x match // keep in sync with UnapplyMethodsImpl.selfUnApply
1437+
case x: (tpd.UnApply & x.type) => Some(x)
1438+
case x: (tpd.Typed & x.type) if x.expr.isInstanceOf[tpd.UnApply] => Some(x)
1439+
case _ => None
14391440
end UnapplyTypeTest
14401441

14411442
object Unapply extends UnapplyModule:
@@ -1447,10 +1448,14 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, QuoteUnpickl
14471448

14481449
object UnapplyMethodsImpl extends UnapplyMethods:
14491450
extension (self: Unapply):
1450-
def fun: Term = self.fun
1451-
def implicits: List[Term] = self.implicits
1452-
def patterns: List[Tree] = effectivePatterns(self.patterns)
1453-
end extension
1451+
def fun: Term = selfUnApply(self).fun
1452+
def implicits: List[Term] = selfUnApply(self).implicits
1453+
def patterns: List[Tree] = effectivePatterns(selfUnApply(self).patterns)
1454+
end extension
1455+
private def selfUnApply(self: Unapply): tpd.UnApply =
1456+
self match // keep in sync with UnapplyTypeTest
1457+
case self: tpd.UnApply => self
1458+
case self: tpd.Typed => self.expr.asInstanceOf[tpd.UnApply]
14541459
private def effectivePatterns(patterns: List[Tree]): List[Tree] =
14551460
patterns match
14561461
case patterns0 :+ dotc.ast.Trees.SeqLiteral(elems, _) => patterns0 ::: elems

0 commit comments

Comments
 (0)