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