@@ -531,27 +531,16 @@ object SpaceEngine {
531531 val mt : MethodType = unapp.widen match {
532532 case mt : MethodType => mt
533533 case pt : PolyType =>
534- if unappSym.is(Synthetic ) then
535- val mt = pt.resultType.asInstanceOf [MethodType ]
536- val unapplyArgType = mt.paramInfos.head
537- val targs = scrutineeTp.baseType(unapplyArgType.classSymbol) match
538- case AppliedType (_, targs) => targs
539- case _ =>
540- // Typically when the scrutinee is Null or Nothing (see i5067 and i5067b)
541- // For performance, do `variances(unapplyArgType)` but without using TypeVars
542- // so just find the variance, so we know if to min/max to the LB/UB or use a wildcard.
543- object accu extends TypeAccumulator [VarianceMap [TypeParamRef ]]:
544- def apply (vmap : VarianceMap [TypeParamRef ], tp : Type ) = tp match
545- case tp : TypeParamRef if tp.binder eq pt => vmap.recordLocalVariance(tp, variance)
546- case _ => foldOver(vmap, tp)
547- val vs = accu(VarianceMap .empty[TypeParamRef ], unapplyArgType)
548- pt.paramRefs.map: p =>
549- vs.computedVariance(p).uncheckedNN match
550- case - 1 => p.paramInfo.lo
551- case 1 => p.paramInfo.hi
552- case _ => WildcardType (p.paramInfo)
534+ scrutineeTp match
535+ case AppliedType (tycon, targs)
536+ if unappSym.is(Synthetic )
537+ && (pt.resultType.asInstanceOf [MethodType ].paramInfos.head.typeConstructor eq tycon) =>
538+ // Special case synthetic unapply/unapplySeq's
539+ // Provided the shapes of the types match:
540+ // the scrutinee type being unapplied and
541+ // the unapply parameter type
553542 pt.instantiate(targs).asInstanceOf [MethodType ]
554- else
543+ case _ =>
555544 val locked = ctx.typerState.ownedVars
556545 val tvars = constrained(pt)
557546 val mt = pt.instantiate(tvars).asInstanceOf [MethodType ]
0 commit comments