Skip to content

Commit b00649a

Browse files
committed
Drop the extra Nothing/Null handling in SpaceEngine.signature
1 parent bdafee6 commit b00649a

File tree

1 file changed

+9
-20
lines changed
  • compiler/src/dotty/tools/dotc/transform/patmat

1 file changed

+9
-20
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -524,27 +524,16 @@ object SpaceEngine {
524524
val mt: MethodType = unapp.widen match {
525525
case mt: MethodType => mt
526526
case pt: PolyType =>
527-
if unappSym.is(Synthetic) then
528-
val mt = pt.resultType.asInstanceOf[MethodType]
529-
val unapplyArgType = mt.paramInfos.head
530-
val targs = scrutineeTp.baseType(unapplyArgType.classSymbol) match
531-
case AppliedType(_, targs) => targs
532-
case _ =>
533-
// Typically when the scrutinee is Null or Nothing (see i5067 and i5067b)
534-
// For performance, do `variances(unapplyArgType)` but without using TypeVars
535-
// so just find the variance, so we know if to min/max to the LB/UB or use a wildcard.
536-
object accu extends TypeAccumulator[VarianceMap[TypeParamRef]]:
537-
def apply(vmap: VarianceMap[TypeParamRef], tp: Type) = tp match
538-
case tp: TypeParamRef if tp.binder eq pt => vmap.recordLocalVariance(tp, variance)
539-
case _ => foldOver(vmap, tp)
540-
val vs = accu(VarianceMap.empty[TypeParamRef], unapplyArgType)
541-
pt.paramRefs.map: p =>
542-
vs.computedVariance(p).uncheckedNN match
543-
case -1 => p.paramInfo.lo
544-
case 1 => p.paramInfo.hi
545-
case _ => WildcardType(p.paramInfo)
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
546535
pt.instantiate(targs).asInstanceOf[MethodType]
547-
else
536+
case _ =>
548537
val locked = ctx.typerState.ownedVars
549538
val tvars = constrained(pt)
550539
val mt = pt.instantiate(tvars).asInstanceOf[MethodType]

0 commit comments

Comments
 (0)