@@ -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 .*
@@ -525,14 +525,25 @@ object SpaceEngine {
525525 val mt : MethodType = unapp.widen match {
526526 case mt : MethodType => mt
527527 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 _ =>
528538 val locked = ctx.typerState.ownedVars
529539 val tvars = constrained(pt)
530540 val mt = pt.instantiate(tvars).asInstanceOf [MethodType ]
531- scrutineeTp <:< mt.paramInfos(0 )
541+ val unapplyArgType = mt.paramInfos.head
542+ scrutineeTp <:< unapplyArgType
532543 // force type inference to infer a narrower type: could be singleton
533544 // 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 )
536547 if ! (ctx.typerState.ownedVars -- locked).isEmpty then
537548 // constraining can create type vars out of wildcard types
538549 // (in legalBound, by using a LevelAvoidMap)
@@ -544,7 +555,7 @@ object SpaceEngine {
544555 // but I'd rather have an unassigned new-new type var, than an infinite loop.
545556 // After all, there's nothing strictly "wrong" with unassigned type vars,
546557 // it just fails TreeChecker's linting.
547- maximizeType(mt.paramInfos( 0 ) , Spans .NoSpan )
558+ maximizeType(unapplyArgType , Spans .NoSpan )
548559 mt
549560 }
550561
0 commit comments