From 535f2306d6848ccd374755467230d557a09f4f36 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 18 Jan 2024 10:22:46 +0100 Subject: [PATCH] Move `unapplyImplicits` to the same level as other helpers in `typedUnapply` --- .../dotty/tools/dotc/typer/Applications.scala | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index b48222d48dc5..452c6d197310 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1439,6 +1439,20 @@ trait Applications extends Compatibility { else (unapplyFn, unapplyAppCall) end inlinedUnapplyFnAndApp + def unapplyImplicits(dummyArg: Tree, unapp: Tree): List[Tree] = + val res = List.newBuilder[Tree] + def loop(unapp: Tree): Unit = unapp match + case Apply(Apply(unapply, `dummyArg` :: Nil), args2) => assert(args2.nonEmpty); res ++= args2 + case Apply(unapply, `dummyArg` :: Nil) => + case Inlined(u, _, _) => loop(u) + case DynamicUnapply(_) => report.error(em"Structural unapply is not supported", unapplyFn.srcPos) + case Apply(fn, args) => assert(args.nonEmpty); loop(fn); res ++= args + case _ => ().assertingErrorsReported + + loop(unapp) + res.result() + end unapplyImplicits + /** Add a `Bind` node for each `bound` symbol in a type application `unapp` */ def addBinders(unapp: Tree, bound: List[Symbol]) = unapp match { case TypeApply(fn, args) => @@ -1482,20 +1496,6 @@ trait Applications extends Compatibility { typedExpr(untpd.TypedSplice(Apply(unapplyFn, dummyArg :: Nil))) inlinedUnapplyFnAndApp(dummyArg, unapplyAppCall) - def unapplyImplicits(unapp: Tree): List[Tree] = { - val res = List.newBuilder[Tree] - def loop(unapp: Tree): Unit = unapp match { - case Apply(Apply(unapply, `dummyArg` :: Nil), args2) => assert(args2.nonEmpty); res ++= args2 - case Apply(unapply, `dummyArg` :: Nil) => - case Inlined(u, _, _) => loop(u) - case DynamicUnapply(_) => report.error(em"Structural unapply is not supported", unapplyFn.srcPos) - case Apply(fn, args) => assert(args.nonEmpty); loop(fn); res ++= args - case _ => ().assertingErrorsReported - } - loop(unapp) - res.result() - } - var argTypes = unapplyArgs(unapplyApp.tpe, unapplyFn, args, tree.srcPos) for (argType <- argTypes) assert(!isBounds(argType), unapplyApp.tpe.show) val bunchedArgs = argTypes match { @@ -1510,7 +1510,7 @@ trait Applications extends Compatibility { List.fill(argTypes.length - args.length)(WildcardType) } val unapplyPatterns = bunchedArgs.lazyZip(argTypes) map (typed(_, _)) - val result = assignType(cpy.UnApply(tree)(newUnapplyFn, unapplyImplicits(unapplyApp), unapplyPatterns), ownType) + val result = assignType(cpy.UnApply(tree)(newUnapplyFn, unapplyImplicits(dummyArg, unapplyApp), unapplyPatterns), ownType) unapp.println(s"unapply patterns = $unapplyPatterns") if (ownType.stripped eq selType.stripped) || ownType.isError then result else tryWithTypeTest(Typed(result, TypeTree(ownType)), selType)