@@ -335,13 +335,25 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
335
335
case Bind (_, pat) => project(pat)
336
336
case SeqLiteral (pats, _) => projectSeq(pats)
337
337
case UnApply (fun, _, pats) =>
338
- if (fun.symbol.name == nme.unapplySeq)
339
- if (fun.symbol.owner == scalaSeqFactoryClass)
340
- projectSeq(pats)
341
- else
338
+ if (fun.symbol.owner == scalaSeqFactoryClass && fun.symbol.name == nme.unapplySeq)
339
+ projectSeq(pats)
340
+ else {
341
+ var tp = fun.tpe.widen.finalResultType
342
+ var arity = productArity(tp, fun.sourcePos)
343
+ if (arity <= 0 ) {
344
+ tp = fun.tpe.widen.finalResultType.select(nme.get).finalResultType.widen
345
+ if (pats.length == 1 )
346
+ return Prod (erase(pat.tpe.stripAnnots), fun.tpe, fun.symbol, pats.map(project), irrefutable(fun))
347
+ arity = productSelectorTypes(tp, fun.sourcePos).size
348
+ }
349
+
350
+ if (arity > 0 && arity != pats.length)
351
+ Prod (erase(pat.tpe.stripAnnots), fun.tpe, fun.symbol, pats.take(arity - 1 ).map(project) :+ projectSeq(pats.drop(arity - 1 )), irrefutable(fun))
352
+ else if (arity <= 0 && unapplySeqTypeElemTp(tp).exists)
342
353
Prod (erase(pat.tpe.stripAnnots), fun.tpe, fun.symbol, projectSeq(pats) :: Nil , irrefutable(fun))
343
- else
344
- Prod (erase(pat.tpe.stripAnnots), fun.tpe, fun.symbol, pats.map(project), irrefutable(fun))
354
+ else
355
+ Prod (erase(pat.tpe.stripAnnots), fun.tpe, fun.symbol, pats.map(project), irrefutable(fun))
356
+ }
345
357
case Typed (pat @ UnApply (_, _, _), _) => project(pat)
346
358
case Typed (expr, tpt) =>
347
359
Typ (erase(expr.tpe.stripAnnots), true )
@@ -424,17 +436,27 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
424
436
List ()
425
437
else {
426
438
val isUnapplySeq = unappSym.name == nme.unapplySeq
427
- if (productArity(mt.finalResultType, unappSym.sourcePos) > 0 && ! isUnapplySeq) {
428
- productSelectors(mt.finalResultType).take(argLen)
429
- .map(_.info.asSeenFrom(mt.finalResultType, mt.resultType.classSymbol).widenExpr)
439
+ val arity = productArity(mt.finalResultType, unappSym.sourcePos)
440
+ if (arity > 0 && ! isUnapplySeq) {
441
+ if (arity != argLen) {
442
+ val sels = productSeqSelectors(mt.finalResultType, arity, unappSym.sourcePos)
443
+ sels.init :+ scalaListType.appliedTo(sels.last)
444
+ }
445
+ else
446
+ productSelectors(mt.finalResultType)
447
+ .map(_.info.asSeenFrom(mt.finalResultType, mt.resultType.classSymbol).widenExpr)
430
448
}
431
449
else {
432
450
val resTp = mt.finalResultType.select(nme.get).finalResultType.widen
433
- if (isUnapplySeq) scalaListType.appliedTo(resTp.argTypes.head) :: Nil
434
- else if (argLen == 0 ) Nil
435
- else if (isProductMatch(resTp, argLen))
451
+ val arity = productArity(resTp, unappSym.sourcePos)
452
+ if (isUnapplySeq && arity < 0 ) scalaListType.appliedTo(resTp.argTypes.head) :: Nil
453
+ else if (argLen == 1 ) resTp :: Nil
454
+ else if (arity > 0 && arity != argLen) {
455
+ val sels = productSeqSelectors(resTp, arity, unappSym.sourcePos)
456
+ sels.init :+ scalaListType.appliedTo(sels.last)
457
+ }
458
+ else
436
459
productSelectors(resTp).map(_.info.asSeenFrom(resTp, resTp.classSymbol).widenExpr)
437
- else resTp :: Nil
438
460
}
439
461
}
440
462
0 commit comments