@@ -5847,7 +5847,7 @@ object Types {
58475847 tp.derivedAppliedType(tycon, args.map(rangeToBounds)) match
58485848 case tp1 : AppliedType if tp1.isUnreducibleWild =>
58495849 // don't infer a type that would trigger an error later in
5850- // Checling .checkAppliedType; fall through to default handling instead
5850+ // Checking .checkAppliedType; fall through to default handling instead
58515851 case tp1 =>
58525852 return tp1
58535853 end if
@@ -5856,7 +5856,7 @@ object Types {
58565856 // non-range arguments L1, ..., Ln and H1, ..., Hn such that
58575857 // C[L1, ..., Ln] <: C[H1, ..., Hn] by taking the right limits of
58585858 // ranges that appear in as co- or contravariant arguments.
5859- // Fail for non-variant argument ranges.
5859+ // Fail for non-variant argument ranges (see use-site else branch below) .
58605860 // If successful, the L-arguments are in loBut, the H-arguments in hiBuf.
58615861 // @return operation succeeded for all arguments.
58625862 def distributeArgs (args : List [Type ], tparams : List [ParamInfo ]): Boolean = args match {
@@ -5877,11 +5877,18 @@ object Types {
58775877 if (distributeArgs(args, tp.tyconTypeParams))
58785878 range(tp.derivedAppliedType(tycon, loBuf.toList),
58795879 tp.derivedAppliedType(tycon, hiBuf.toList))
5880- else range(defn.NothingType , defn.AnyType )
5881- // TODO: can we give a better bound than `topType`?
5880+ else if tycon.isLambdaSub || args.exists(isRangeOfNonTermTypes) then
5881+ range(defn.NothingType , defn.AnyType )
5882+ else
5883+ // See lampepfl/dotty#14152
5884+ range(defn.NothingType , tp.derivedAppliedType(tycon, args.map(rangeToBounds)))
58825885 else tp.derivedAppliedType(tycon, args)
58835886 }
58845887
5888+ private def isRangeOfNonTermTypes (tp : Type ): Boolean = tp match
5889+ case Range (lo, hi) => ! lo.isInstanceOf [TermType ] || ! hi.isInstanceOf [TermType ]
5890+ case _ => false
5891+
58855892 override protected def derivedAndType (tp : AndType , tp1 : Type , tp2 : Type ): Type =
58865893 if (isRange(tp1) || isRange(tp2)) range(lower(tp1) & lower(tp2), upper(tp1) & upper(tp2))
58875894 else tp.derivedAndType(tp1, tp2)
0 commit comments