Skip to content

Commit 25d2ec1

Browse files
committed
Move unapplyImplicits to the same level as other helpers in typedUnapply
1 parent 5648f12 commit 25d2ec1

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

+15-15
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,20 @@ trait Applications extends Compatibility {
14391439
else (unapplyFn, unapplyAppCall)
14401440
end inlinedUnapplyFnAndApp
14411441

1442+
def unapplyImplicits(dummyArg: Tree, unapp: Tree): List[Tree] = {
1443+
val res = List.newBuilder[Tree]
1444+
def loop(unapp: Tree): Unit = unapp match {
1445+
case Apply(Apply(unapply, `dummyArg` :: Nil), args2) => assert(args2.nonEmpty); res ++= args2
1446+
case Apply(unapply, `dummyArg` :: Nil) =>
1447+
case Inlined(u, _, _) => loop(u)
1448+
case DynamicUnapply(_) => report.error(em"Structural unapply is not supported", unapplyFn.srcPos)
1449+
case Apply(fn, args) => assert(args.nonEmpty); loop(fn); res ++= args
1450+
case _ => ().assertingErrorsReported
1451+
}
1452+
loop(unapp)
1453+
res.result()
1454+
}
1455+
14421456
/** Add a `Bind` node for each `bound` symbol in a type application `unapp` */
14431457
def addBinders(unapp: Tree, bound: List[Symbol]) = unapp match {
14441458
case TypeApply(fn, args) =>
@@ -1482,20 +1496,6 @@ trait Applications extends Compatibility {
14821496
typedExpr(untpd.TypedSplice(Apply(unapplyFn, dummyArg :: Nil)))
14831497
inlinedUnapplyFnAndApp(dummyArg, unapplyAppCall)
14841498

1485-
def unapplyImplicits(unapp: Tree): List[Tree] = {
1486-
val res = List.newBuilder[Tree]
1487-
def loop(unapp: Tree): Unit = unapp match {
1488-
case Apply(Apply(unapply, `dummyArg` :: Nil), args2) => assert(args2.nonEmpty); res ++= args2
1489-
case Apply(unapply, `dummyArg` :: Nil) =>
1490-
case Inlined(u, _, _) => loop(u)
1491-
case DynamicUnapply(_) => report.error(em"Structural unapply is not supported", unapplyFn.srcPos)
1492-
case Apply(fn, args) => assert(args.nonEmpty); loop(fn); res ++= args
1493-
case _ => ().assertingErrorsReported
1494-
}
1495-
loop(unapp)
1496-
res.result()
1497-
}
1498-
14991499
var argTypes = unapplyArgs(unapplyApp.tpe, unapplyFn, args, tree.srcPos)
15001500
for (argType <- argTypes) assert(!isBounds(argType), unapplyApp.tpe.show)
15011501
val bunchedArgs = argTypes match {
@@ -1510,7 +1510,7 @@ trait Applications extends Compatibility {
15101510
List.fill(argTypes.length - args.length)(WildcardType)
15111511
}
15121512
val unapplyPatterns = bunchedArgs.lazyZip(argTypes) map (typed(_, _))
1513-
val result = assignType(cpy.UnApply(tree)(newUnapplyFn, unapplyImplicits(unapplyApp), unapplyPatterns), ownType)
1513+
val result = assignType(cpy.UnApply(tree)(newUnapplyFn, unapplyImplicits(dummyArg, unapplyApp), unapplyPatterns), ownType)
15141514
unapp.println(s"unapply patterns = $unapplyPatterns")
15151515
if (ownType.stripped eq selType.stripped) || ownType.isError then result
15161516
else tryWithTypeTest(Typed(result, TypeTree(ownType)), selType)

0 commit comments

Comments
 (0)