@@ -706,9 +706,34 @@ object TypeOps:
706706 def loop (args : List [Tree ], boundss : List [TypeBounds ]): Unit = args match
707707 case arg :: args1 => boundss match
708708 case bounds :: boundss1 =>
709+
710+ // Drop caps.Pure from a bound (1) at the top-level, (2) in an `&`, (3) under a type lambda.
711+ def dropPure (tp : Type ): Option [Type ] = tp match
712+ case tp @ AndType (tp1, tp2) =>
713+ dropPure(tp1) match
714+ case Some (tp1o) =>
715+ dropPure(tp2) match
716+ case Some (tp2o) => Some (tp.derivedAndType(tp1o, tp2o))
717+ case None => Some (tp1o)
718+ case None =>
719+ dropPure(tp2)
720+ case tp : HKTypeLambda =>
721+ for rt <- dropPure(tp.resType) yield
722+ tp.derivedLambdaType(resType = rt)
723+ case _ =>
724+ if tp.typeSymbol == defn.PureClass then None
725+ else Some (tp)
726+
727+ val relevantBounds =
728+ if Feature .ccEnabled then bounds
729+ else
730+ // Drop caps.Pure from bound, it should be checked only when capture checking is enabled
731+ dropPure(bounds.hi).match
732+ case Some (hi1) => bounds.derivedTypeBounds(bounds.lo, hi1)
733+ case None => TypeBounds (bounds.lo, defn.AnyKindType )
709734 arg.tpe match
710- case TypeBounds (lo, hi) => checkOverlapsBounds(lo, hi, arg, bounds )
711- case tp => checkOverlapsBounds(tp, tp, arg, bounds )
735+ case TypeBounds (lo, hi) => checkOverlapsBounds(lo, hi, arg, relevantBounds )
736+ case tp => checkOverlapsBounds(tp, tp, arg, relevantBounds )
712737 loop(args1, boundss1)
713738 case _ =>
714739 case _ =>
0 commit comments