@@ -647,9 +647,9 @@ trait ConstraintHandling {
647
647
* At this point we also drop the @Repeated annotation to avoid inferring type arguments with it,
648
648
* as those could leak the annotation to users (see run/inferred-repeated-result).
649
649
*/
650
- def widenInferred (inst : Type , bound : Type , widenUnions : Boolean )(using Context ): Type =
650
+ def widenInferred (inst : Type , bound : Type , widen : Widen )(using Context ): Type =
651
651
def widenOr (tp : Type ) =
652
- if widenUnions then
652
+ if widen == Widen . Unions then
653
653
val tpw = tp.widenUnion
654
654
if tpw ne tp then
655
655
if tpw.isTransparent() then
@@ -667,14 +667,10 @@ trait ConstraintHandling {
667
667
val tpw = tp.widenSingletons(skipSoftUnions)
668
668
if (tpw ne tp) && (tpw <:< bound) then tpw else tp
669
669
670
- def isSingleton (tp : Type ): Boolean = tp match
671
- case WildcardType (optBounds) => optBounds.exists && isSingleton(optBounds.bounds.hi)
672
- case _ => isSubTypeWhenFrozen(tp, defn.SingletonType )
673
-
674
670
val wideInst =
675
- if isSingleton( bound) then inst
671
+ if widen == Widen . None || bound.isSingletonBounded then inst
676
672
else
677
- val widenedFromSingle = widenSingle(inst, skipSoftUnions = widenUnions )
673
+ val widenedFromSingle = widenSingle(inst, skipSoftUnions = widen == Widen . Unions )
678
674
val widenedFromUnion = widenOr(widenedFromSingle)
679
675
val widened = dropTransparentTraits(widenedFromUnion, bound)
680
676
widenIrreducible(widened)
@@ -711,18 +707,18 @@ trait ConstraintHandling {
711
707
* The instance type is not allowed to contain references to types nested deeper
712
708
* than `maxLevel`.
713
709
*/
714
- def instanceType (param : TypeParamRef , fromBelow : Boolean , widenUnions : Boolean , maxLevel : Int )(using Context ): Type = {
710
+ def instanceType (param : TypeParamRef , fromBelow : Boolean , widen : Widen , maxLevel : Int )(using Context ): Type = {
715
711
val approx = approximation(param, fromBelow, maxLevel).simplified
716
712
if fromBelow then
717
- val widened = widenInferred(approx, param, widenUnions )
713
+ val widened = widenInferred(approx, param, widen )
718
714
// Widening can add extra constraints, in particular the widened type might
719
715
// be a type variable which is now instantiated to `param`, and therefore
720
716
// cannot be used as an instantiation of `param` without creating a loop.
721
717
// If that happens, we run `instanceType` again to find a new instantiation.
722
718
// (we do not check for non-toplevel occurrences: those should never occur
723
719
// since `addOneBound` disallows recursive lower bounds).
724
720
if constraint.occursAtToplevel(param, widened) then
725
- instanceType(param, fromBelow, widenUnions , maxLevel)
721
+ instanceType(param, fromBelow, widen , maxLevel)
726
722
else
727
723
widened
728
724
else
0 commit comments