@@ -537,8 +537,7 @@ object SpaceEngine {
537537 // force type inference to infer a narrower type: could be singleton
538538 // see tests/patmat/i4227.scala
539539 mt.paramInfos(0 ) <:< scrutineeTp
540- instantiateSelected(mt, tvars)
541- isFullyDefined(mt, ForceDegree .all)
540+ maximizeType(mt.paramInfos(0 ), Spans .NoSpan )
542541 mt
543542 }
544543
@@ -552,7 +551,7 @@ object SpaceEngine {
552551 // Case unapplySeq:
553552 // 1. return the type `List[T]` where `T` is the element type of the unapplySeq return type `Seq[T]`
554553
555- val resTp = ctx.typeAssigner.safeSubstMethodParams(mt, scrutineeTp :: Nil ).finalResultType
554+ val resTp = wildApprox( ctx.typeAssigner.safeSubstMethodParams(mt, scrutineeTp :: Nil ).finalResultType)
556555
557556 val sig =
558557 if (resTp.isRef(defn.BooleanClass ))
@@ -573,14 +572,14 @@ object SpaceEngine {
573572 if (arity > 0 )
574573 productSelectorTypes(resTp, unappSym.srcPos)
575574 else {
576- val getTp = resTp.select( nme.get).finalResultType.widenTermRefExpr
575+ val getTp = extractorMemberType(resTp, nme.get, unappSym.srcPos)
577576 if (argLen == 1 ) getTp :: Nil
578577 else productSelectorTypes(getTp, unappSym.srcPos)
579578 }
580579 }
581580 }
582581
583- sig.map(_.annotatedToRepeated)
582+ sig.map { case tp : WildcardType => tp.bounds.hi case tp => tp }
584583 }
585584
586585 /** Whether the extractor covers the given type */
@@ -625,7 +624,21 @@ object SpaceEngine {
625624 // For instance, from i15029, `decompose((X | Y).Field[T]) = [X.Field[T], Y.Field[T]]`.
626625 parts.map(tp.derivedAppliedType(_, targs))
627626
628- case tp if tp.isDecomposableToChildren =>
627+ case tpOriginal if tpOriginal.isDecomposableToChildren =>
628+ // isDecomposableToChildren uses .classSymbol.is(Sealed)
629+ // But that classSymbol could be from an AppliedType
630+ // where the type constructor is a non-class type
631+ // E.g. t11620 where `?1.AA[X]` returns as "sealed"
632+ // but using that we're not going to infer A1[X] and A2[X]
633+ // but end up with A1[<?>] and A2[<?>].
634+ // So we widen (like AppliedType superType does) away
635+ // non-class type constructors.
636+ def getAppliedClass (tp : Type ): Type = tp match
637+ case tp @ AppliedType (_ : HKTypeLambda , _) => tp
638+ case tp @ AppliedType (tycon : TypeRef , _) if tycon.symbol.isClass => tp
639+ case tp @ AppliedType (tycon : TypeProxy , _) => getAppliedClass(tycon.superType.applyIfParameterized(tp.args))
640+ case tp => tp
641+ val tp = getAppliedClass(tpOriginal)
629642 def getChildren (sym : Symbol ): List [Symbol ] =
630643 sym.children.flatMap { child =>
631644 if child eq sym then List (sym) // i3145: sealed trait Baz, val x = new Baz {}, Baz.children returns Baz...
0 commit comments