@@ -7,7 +7,7 @@ import core.*
7
7
import Constants .* , Contexts .* , Decorators .* , Flags .* , NullOpsDecorator .* , Symbols .* , Types .*
8
8
import Names .* , NameOps .* , StdNames .*
9
9
import ast .* , tpd .*
10
- import config .Printers .*
10
+ import config .Printers .exhaustivity
11
11
import printing .{ Printer , * }, Texts .*
12
12
import reporting .*
13
13
import typer .* , Applications .* , Inferencing .* , ProtoTypes .*
@@ -525,14 +525,25 @@ object SpaceEngine {
525
525
val mt : MethodType = unapp.widen match {
526
526
case mt : MethodType => mt
527
527
case pt : PolyType =>
528
+ scrutineeTp match
529
+ case AppliedType (tycon, targs)
530
+ if unappSym.is(Synthetic )
531
+ && (pt.resultType.asInstanceOf [MethodType ].paramInfos.head.typeConstructor eq tycon) =>
532
+ // Special case synthetic unapply/unapplySeq's
533
+ // Provided the shapes of the types match:
534
+ // the scrutinee type being unapplied and
535
+ // the unapply parameter type
536
+ pt.instantiate(targs).asInstanceOf [MethodType ]
537
+ case _ =>
528
538
val locked = ctx.typerState.ownedVars
529
539
val tvars = constrained(pt)
530
540
val mt = pt.instantiate(tvars).asInstanceOf [MethodType ]
531
- scrutineeTp <:< mt.paramInfos(0 )
541
+ val unapplyArgType = mt.paramInfos.head
542
+ scrutineeTp <:< unapplyArgType
532
543
// force type inference to infer a narrower type: could be singleton
533
544
// see tests/patmat/i4227.scala
534
- mt.paramInfos( 0 ) <:< scrutineeTp
535
- maximizeType(mt.paramInfos( 0 ) , Spans .NoSpan )
545
+ unapplyArgType <:< scrutineeTp
546
+ maximizeType(unapplyArgType , Spans .NoSpan )
536
547
if ! (ctx.typerState.ownedVars -- locked).isEmpty then
537
548
// constraining can create type vars out of wildcard types
538
549
// (in legalBound, by using a LevelAvoidMap)
@@ -544,7 +555,7 @@ object SpaceEngine {
544
555
// but I'd rather have an unassigned new-new type var, than an infinite loop.
545
556
// After all, there's nothing strictly "wrong" with unassigned type vars,
546
557
// it just fails TreeChecker's linting.
547
- maximizeType(mt.paramInfos( 0 ) , Spans .NoSpan )
558
+ maximizeType(unapplyArgType , Spans .NoSpan )
548
559
mt
549
560
}
550
561
0 commit comments