@@ -47,7 +47,7 @@ object Applications {
4747 val ref = extractorMember(tp, name)
4848 if (ref.isOverloaded)
4949 errorType(i " Overloaded reference to $ref is not allowed in extractor " , errorPos)
50- ref.info.widenExpr.dealias
50+ ref.info.widenExpr.annotatedToRepeated. dealias
5151 }
5252
5353 /** Does `tp` fit the "product match" conditions as an unapply result type
@@ -93,7 +93,10 @@ object Applications {
9393 def getTp = extractorMemberType(unapplyResult, nme.get, pos)
9494
9595 def fail = {
96- ctx.error(i " $unapplyResult is not a valid result type of an $unapplyName method of an extractor " , pos)
96+ val addendum =
97+ if (ctx.scala2Mode && unapplyName == nme.unapplySeq)
98+ " \n You might want to try to rewrite the extractor to use `unapply` instead."
99+ ctx.error(em " $unapplyResult is not a valid result type of an $unapplyName method of an extractor $addendum" , pos)
97100 Nil
98101 }
99102
@@ -959,13 +962,19 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
959962
960963 var argTypes = unapplyArgs(unapplyApp.tpe, unapplyFn, args, tree.pos)
961964 for (argType <- argTypes) assert(! argType.isInstanceOf [TypeBounds ], unapplyApp.tpe.show)
962- val bunchedArgs = argTypes match {
963- case argType :: Nil =>
964- if (argType.isRepeatedParam) untpd.SeqLiteral (args, untpd.TypeTree ()) :: Nil
965- else if (args.lengthCompare(1 ) > 0 && ctx.canAutoTuple) untpd.Tuple (args) :: Nil
966- else args
967- case _ => args
968- }
965+ val bunchedArgs =
966+ if (argTypes.nonEmpty && argTypes.last.isRepeatedParam)
967+ args.lastOption match {
968+ case Some (arg @ Typed (argSeq, _)) if untpd.isWildcardStarArg(arg) =>
969+ args.init :+ argSeq
970+ case _ =>
971+ val (regularArgs, varArgs) = args.splitAt(argTypes.length - 1 )
972+ regularArgs :+ untpd.SeqLiteral (varArgs, untpd.TypeTree ())
973+ }
974+ else if (argTypes.lengthCompare(1 ) == 0 && args.lengthCompare(1 ) > 0 && ctx.canAutoTuple)
975+ untpd.Tuple (args) :: Nil
976+ else
977+ args
969978 if (argTypes.length != bunchedArgs.length) {
970979 ctx.error(UnapplyInvalidNumberOfArguments (qual, argTypes), tree.pos)
971980 argTypes = argTypes.take(args.length) ++
0 commit comments