@@ -7,7 +7,7 @@ import core.*
77import Constants .* , Contexts .* , Decorators .* , Flags .* , NullOpsDecorator .* , Symbols .* , Types .*
88import Names .* , NameOps .* , StdNames .*
99import ast .* , tpd .*
10- import config .Printers .*
10+ import config .Printers .exhaustivity
1111import printing .{ Printer , * }, Texts .*
1212import reporting .*
1313import typer .* , Applications .* , Inferencing .* , ProtoTypes .*
@@ -524,14 +524,25 @@ object SpaceEngine {
524524 val mt : MethodType = unapp.widen match {
525525 case mt : MethodType => mt
526526 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 _ =>
527537 val locked = ctx.typerState.ownedVars
528538 val tvars = constrained(pt)
529539 val mt = pt.instantiate(tvars).asInstanceOf [MethodType ]
530- scrutineeTp <:< mt.paramInfos(0 )
540+ val unapplyArgType = mt.paramInfos.head
541+ scrutineeTp <:< unapplyArgType
531542 // force type inference to infer a narrower type: could be singleton
532543 // 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 )
535546 if ! (ctx.typerState.ownedVars -- locked).isEmpty then
536547 // constraining can create type vars out of wildcard types
537548 // (in legalBound, by using a LevelAvoidMap)
@@ -543,7 +554,7 @@ object SpaceEngine {
543554 // but I'd rather have an unassigned new-new type var, than an infinite loop.
544555 // After all, there's nothing strictly "wrong" with unassigned type vars,
545556 // it just fails TreeChecker's linting.
546- maximizeType(mt.paramInfos( 0 ) , Spans .NoSpan )
557+ maximizeType(unapplyArgType , Spans .NoSpan )
547558 mt
548559 }
549560
0 commit comments