@@ -1423,6 +1423,20 @@ trait Applications extends Compatibility {
14231423 else (unapplyFn, unapplyAppCall)
14241424 end inlinedUnapplyFnAndApp
14251425
1426+ def unapplyImplicits (dummyArg : Tree , unapp : Tree ): List [Tree ] =
1427+ val res = List .newBuilder[Tree ]
1428+ def loop (unapp : Tree ): Unit = unapp match
1429+ case Apply (Apply (unapply, `dummyArg` :: Nil ), args2) => assert(args2.nonEmpty); res ++= args2
1430+ case Apply (unapply, `dummyArg` :: Nil ) =>
1431+ case Inlined (u, _, _) => loop(u)
1432+ case DynamicUnapply (_) => report.error(em " Structural unapply is not supported " , unapplyFn.srcPos)
1433+ case Apply (fn, args) => assert(args.nonEmpty); loop(fn); res ++= args
1434+ case _ => ().assertingErrorsReported
1435+
1436+ loop(unapp)
1437+ res.result()
1438+ end unapplyImplicits
1439+
14261440 /** Add a `Bind` node for each `bound` symbol in a type application `unapp` */
14271441 def addBinders (unapp : Tree , bound : List [Symbol ]) = unapp match {
14281442 case TypeApply (fn, args) =>
@@ -1466,20 +1480,6 @@ trait Applications extends Compatibility {
14661480 typedExpr(untpd.TypedSplice (Apply (unapplyFn, dummyArg :: Nil )))
14671481 inlinedUnapplyFnAndApp(dummyArg, unapplyAppCall)
14681482
1469- def unapplyImplicits (unapp : Tree ): List [Tree ] = {
1470- val res = List .newBuilder[Tree ]
1471- def loop (unapp : Tree ): Unit = unapp match {
1472- case Apply (Apply (unapply, `dummyArg` :: Nil ), args2) => assert(args2.nonEmpty); res ++= args2
1473- case Apply (unapply, `dummyArg` :: Nil ) =>
1474- case Inlined (u, _, _) => loop(u)
1475- case DynamicUnapply (_) => report.error(em " Structural unapply is not supported " , unapplyFn.srcPos)
1476- case Apply (fn, args) => assert(args.nonEmpty); loop(fn); res ++= args
1477- case _ => ().assertingErrorsReported
1478- }
1479- loop(unapp)
1480- res.result()
1481- }
1482-
14831483 var argTypes = unapplyArgs(unapplyApp.tpe, unapplyFn, args, tree.srcPos)
14841484 for (argType <- argTypes) assert(! isBounds(argType), unapplyApp.tpe.show)
14851485 val bunchedArgs = argTypes match {
@@ -1494,7 +1494,7 @@ trait Applications extends Compatibility {
14941494 List .fill(argTypes.length - args.length)(WildcardType )
14951495 }
14961496 val unapplyPatterns = bunchedArgs.lazyZip(argTypes) map (typed(_, _))
1497- val result = assignType(cpy.UnApply (tree)(newUnapplyFn, unapplyImplicits(unapplyApp), unapplyPatterns), ownType)
1497+ val result = assignType(cpy.UnApply (tree)(newUnapplyFn, unapplyImplicits(dummyArg, unapplyApp), unapplyPatterns), ownType)
14981498 unapp.println(s " unapply patterns = $unapplyPatterns" )
14991499 if (ownType.stripped eq selType.stripped) || ownType.isError then result
15001500 else tryWithTypeTest(Typed (result, TypeTree (ownType)), selType)
0 commit comments