@@ -579,47 +579,48 @@ object ProtoTypes {
579
579
/** Approximate occurrences of parameter types and uninstantiated typevars
580
580
* by wildcard types.
581
581
*/
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 {
583
583
case tp : NamedType => // default case, inlined for speed
584
584
val isPatternBoundTypeRef = tp.isInstanceOf [TypeRef ] && tp.symbol.is(Flags .Case ) && ! tp.symbol.isClass
585
585
if (isPatternBoundTypeRef) WildcardType (tp.underlying.bounds)
586
586
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 ))
588
588
case tp @ AppliedType (tycon, args) =>
589
- wildApprox(tycon, theMap, seen) match {
589
+ wildApprox(tycon, theMap, seen, internal ) match {
590
590
case _ : WildcardType => WildcardType // this ensures we get a * type
591
591
case tycon1 => tp.derivedAppliedType(tycon1,
592
- args.mapConserve(arg => wildApprox(arg, theMap, seen)))
592
+ args.mapConserve(arg => wildApprox(arg, theMap, seen, internal )))
593
593
}
594
594
case tp : RefinedType => // default case, inlined for speed
595
595
tp.derivedRefinedType(
596
- wildApprox(tp.parent, theMap, seen),
596
+ wildApprox(tp.parent, theMap, seen, internal ),
597
597
tp.refinedName,
598
- wildApprox(tp.refinedInfo, theMap, seen))
598
+ wildApprox(tp.refinedInfo, theMap, seen, internal ))
599
599
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
601
602
case tp @ TypeParamRef (poly, pnum) =>
602
603
def wildApproxBounds (bounds : TypeBounds ) =
603
604
if (seen.contains(tp)) WildcardType
604
- else WildcardType (wildApprox(bounds, theMap, seen + tp).bounds)
605
+ else WildcardType (wildApprox(bounds, theMap, seen + tp, internal ).bounds)
605
606
def unconstrainedApprox = wildApproxBounds(poly.paramInfos(pnum))
606
607
def approxPoly =
607
608
if (ctx.mode.is(Mode .TypevarsMissContext )) unconstrainedApprox
608
609
else
609
610
ctx.typerState.constraint.entry(tp) match {
610
611
case bounds : TypeBounds => wildApproxBounds(bounds)
611
612
case NoType => unconstrainedApprox
612
- case inst => wildApprox(inst, theMap, seen)
613
+ case inst => wildApprox(inst, theMap, seen, internal )
613
614
}
614
615
approxPoly
615
616
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 )))
617
618
case tp : TypeVar =>
618
- wildApprox(tp.underlying, theMap, seen)
619
+ wildApprox(tp.underlying, theMap, seen, internal )
619
620
case tp : AndType =>
620
621
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 )
623
624
def wildBounds (tp : Type ) =
624
625
if (tp.isInstanceOf [WildcardType ]) tp.bounds else TypeBounds .upper(tp)
625
626
if (tp1a.isInstanceOf [WildcardType ] || tp2a.isInstanceOf [WildcardType ])
@@ -630,33 +631,39 @@ object ProtoTypes {
630
631
approxAnd
631
632
case tp : OrType =>
632
633
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 )
635
636
if (tp1a.isInstanceOf [WildcardType ] || tp2a.isInstanceOf [WildcardType ])
636
637
WildcardType (tp1a.bounds | tp2a.bounds)
637
638
else
638
639
tp.derivedOrType(tp1a, tp2a)
639
640
}
640
641
approxOr
641
642
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 )
643
644
case tp : ViewProto =>
644
645
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 ))
647
648
case _ : ThisType | _ : BoundType => // default case, inlined for speed
648
649
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
+ )
649
656
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 ))
651
658
.mapOver(tp)
652
659
}
653
660
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 )
655
662
656
663
@ sharable object AssignProto extends UncachedGroundType with MatchAlways
657
664
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 )
660
667
}
661
668
662
669
/** Dummy tree to be used as an argument of a FunProto or ViewProto type */
0 commit comments