@@ -579,47 +579,48 @@ object ProtoTypes {
579579 /** Approximate occurrences of parameter types and uninstantiated typevars
580580 * by wildcard types.
581581 */
582- private def wildApprox (tp : Type , theMap : WildApproxMap , seen : Set [TypeParamRef ])(implicit ctx : Context ): Type = tp match {
582+ private def wildApprox (tp : Type , theMap : WildApproxMap , seen : Set [TypeParamRef ], internal : Set [ TypeLambda ] )(implicit ctx : Context ): Type = tp match {
583583 case tp : NamedType => // default case, inlined for speed
584584 val isPatternBoundTypeRef = tp.isInstanceOf [TypeRef ] && tp.symbol.is(Flags .Case ) && ! tp.symbol.isClass
585585 if (isPatternBoundTypeRef) WildcardType (tp.underlying.bounds)
586586 else if (tp.symbol.isStatic || (tp.prefix `eq` NoPrefix )) tp
587- else tp.derivedSelect(wildApprox(tp.prefix, theMap, seen))
587+ else tp.derivedSelect(wildApprox(tp.prefix, theMap, seen, internal ))
588588 case tp @ AppliedType (tycon, args) =>
589- wildApprox(tycon, theMap, seen) match {
589+ wildApprox(tycon, theMap, seen, internal ) match {
590590 case _ : WildcardType => WildcardType // this ensures we get a * type
591591 case tycon1 => tp.derivedAppliedType(tycon1,
592- args.mapConserve(arg => wildApprox(arg, theMap, seen)))
592+ args.mapConserve(arg => wildApprox(arg, theMap, seen, internal )))
593593 }
594594 case tp : RefinedType => // default case, inlined for speed
595595 tp.derivedRefinedType(
596- wildApprox(tp.parent, theMap, seen),
596+ wildApprox(tp.parent, theMap, seen, internal ),
597597 tp.refinedName,
598- wildApprox(tp.refinedInfo, theMap, seen))
598+ wildApprox(tp.refinedInfo, theMap, seen, internal ))
599599 case tp : AliasingBounds => // default case, inlined for speed
600- tp.derivedAlias(wildApprox(tp.alias, theMap, seen))
600+ tp.derivedAlias(wildApprox(tp.alias, theMap, seen, internal))
601+ case tp @ TypeParamRef (tl, _) if internal.contains(tl) => tp
601602 case tp @ TypeParamRef (poly, pnum) =>
602603 def wildApproxBounds (bounds : TypeBounds ) =
603604 if (seen.contains(tp)) WildcardType
604- else WildcardType (wildApprox(bounds, theMap, seen + tp).bounds)
605+ else WildcardType (wildApprox(bounds, theMap, seen + tp, internal ).bounds)
605606 def unconstrainedApprox = wildApproxBounds(poly.paramInfos(pnum))
606607 def approxPoly =
607608 if (ctx.mode.is(Mode .TypevarsMissContext )) unconstrainedApprox
608609 else
609610 ctx.typerState.constraint.entry(tp) match {
610611 case bounds : TypeBounds => wildApproxBounds(bounds)
611612 case NoType => unconstrainedApprox
612- case inst => wildApprox(inst, theMap, seen)
613+ case inst => wildApprox(inst, theMap, seen, internal )
613614 }
614615 approxPoly
615616 case TermParamRef (mt, pnum) =>
616- WildcardType (TypeBounds .upper(wildApprox(mt.paramInfos(pnum), theMap, seen)))
617+ WildcardType (TypeBounds .upper(wildApprox(mt.paramInfos(pnum), theMap, seen, internal )))
617618 case tp : TypeVar =>
618- wildApprox(tp.underlying, theMap, seen)
619+ wildApprox(tp.underlying, theMap, seen, internal )
619620 case tp : AndType =>
620621 def approxAnd = {
621- val tp1a = wildApprox(tp.tp1, theMap, seen)
622- val tp2a = wildApprox(tp.tp2, theMap, seen)
622+ val tp1a = wildApprox(tp.tp1, theMap, seen, internal )
623+ val tp2a = wildApprox(tp.tp2, theMap, seen, internal )
623624 def wildBounds (tp : Type ) =
624625 if (tp.isInstanceOf [WildcardType ]) tp.bounds else TypeBounds .upper(tp)
625626 if (tp1a.isInstanceOf [WildcardType ] || tp2a.isInstanceOf [WildcardType ])
@@ -630,33 +631,39 @@ object ProtoTypes {
630631 approxAnd
631632 case tp : OrType =>
632633 def approxOr = {
633- val tp1a = wildApprox(tp.tp1, theMap, seen)
634- val tp2a = wildApprox(tp.tp2, theMap, seen)
634+ val tp1a = wildApprox(tp.tp1, theMap, seen, internal )
635+ val tp2a = wildApprox(tp.tp2, theMap, seen, internal )
635636 if (tp1a.isInstanceOf [WildcardType ] || tp2a.isInstanceOf [WildcardType ])
636637 WildcardType (tp1a.bounds | tp2a.bounds)
637638 else
638639 tp.derivedOrType(tp1a, tp2a)
639640 }
640641 approxOr
641642 case tp : SelectionProto =>
642- tp.derivedSelectionProto(tp.name, wildApprox(tp.memberProto, theMap, seen), NoViewsAllowed )
643+ tp.derivedSelectionProto(tp.name, wildApprox(tp.memberProto, theMap, seen, internal ), NoViewsAllowed )
643644 case tp : ViewProto =>
644645 tp.derivedViewProto(
645- wildApprox(tp.argType, theMap, seen),
646- wildApprox(tp.resultType, theMap, seen))
646+ wildApprox(tp.argType, theMap, seen, internal ),
647+ wildApprox(tp.resultType, theMap, seen, internal ))
647648 case _ : ThisType | _ : BoundType => // default case, inlined for speed
648649 tp
650+ case tl : TypeLambda =>
651+ val internal1 = internal + tl
652+ tl.derivedLambdaType(
653+ paramInfos = tl.paramInfos.mapConserve(wildApprox(_, theMap, seen, internal1).bounds),
654+ resType = wildApprox(tl.resType, theMap, seen, internal1)
655+ )
649656 case _ =>
650- (if (theMap != null && seen.eq(theMap.seen)) theMap else new WildApproxMap (seen))
657+ (if (theMap != null && seen.eq(theMap.seen)) theMap else new WildApproxMap (seen, internal ))
651658 .mapOver(tp)
652659 }
653660
654- final def wildApprox (tp : Type )(implicit ctx : Context ): Type = wildApprox(tp, null , Set .empty)
661+ final def wildApprox (tp : Type )(implicit ctx : Context ): Type = wildApprox(tp, null , Set .empty, Set .empty )
655662
656663 @ sharable object AssignProto extends UncachedGroundType with MatchAlways
657664
658- private [ProtoTypes ] class WildApproxMap (val seen : Set [TypeParamRef ])(implicit ctx : Context ) extends TypeMap {
659- def apply (tp : Type ): Type = wildApprox(tp, this , seen)
665+ private [ProtoTypes ] class WildApproxMap (val seen : Set [TypeParamRef ], val internal : Set [ TypeLambda ] )(implicit ctx : Context ) extends TypeMap {
666+ def apply (tp : Type ): Type = wildApprox(tp, this , seen, internal )
660667 }
661668
662669 /** Dummy tree to be used as an argument of a FunProto or ViewProto type */
0 commit comments