@@ -1988,7 +1988,8 @@ object Types {
1988
1988
}
1989
1989
1990
1990
/** The argument corresponding to class type parameter `tparam` as seen from
1991
- * prefix `pre`.
1991
+ * prefix `pre`. Can produce a TypeBounds type in case prefix is an & or | type
1992
+ * and parameter is non-variant.
1992
1993
*/
1993
1994
def argForParam (pre : Type )(implicit ctx : Context ): Type = {
1994
1995
val tparam = symbol
@@ -2010,8 +2011,16 @@ object Types {
2010
2011
idx += 1
2011
2012
}
2012
2013
NoType
2013
- case OrType (base1, base2) => argForParam(base1) | argForParam(base2)
2014
- case AndType (base1, base2) => argForParam(base1) & argForParam(base2)
2014
+ case base : AndOrType =>
2015
+ var tp1 = argForParam(base.tp1)
2016
+ var tp2 = argForParam(base.tp2)
2017
+ val variance = tparam.paramVariance
2018
+ if (tp1.isInstanceOf [TypeBounds ] || tp2.isInstanceOf [TypeBounds ] || variance == 0 ) {
2019
+ // compute argument as a type bounds instead of a point type
2020
+ tp1 = tp1.bounds
2021
+ tp2 = tp2.bounds
2022
+ }
2023
+ if (base.isAnd == variance >= 0 ) tp1 & tp2 else tp1 | tp2
2015
2024
case _ =>
2016
2025
if (pre.termSymbol is Package ) argForParam(pre.select(nme.PACKAGE ))
2017
2026
else if (pre.isBottomType) pre
@@ -4414,6 +4423,7 @@ object Types {
4414
4423
protected def range (lo : Type , hi : Type ): Type =
4415
4424
if (variance > 0 ) hi
4416
4425
else if (variance < 0 ) lo
4426
+ else if (lo `eq` hi) lo
4417
4427
else Range (lower(lo), upper(hi))
4418
4428
4419
4429
protected def isRange (tp : Type ): Boolean = tp.isInstanceOf [Range ]
@@ -4462,13 +4472,18 @@ object Types {
4462
4472
* If the expansion is a wildcard parameter reference, convert its
4463
4473
* underlying bounds to a range, otherwise return the expansion.
4464
4474
*/
4465
- def expandParam (tp : NamedType , pre : Type ): Type = tp.argForParam(pre) match {
4466
- case arg @ TypeRef (pre, _) if pre.isArgPrefixOf(arg.symbol) =>
4467
- arg.info match {
4468
- case TypeBounds (lo, hi) => range(atVariance(- variance)(reapply(lo)), reapply(hi))
4469
- case arg => reapply(arg)
4470
- }
4471
- case arg => reapply(arg)
4475
+ def expandParam (tp : NamedType , pre : Type ): Type = {
4476
+ def expandBounds (tp : TypeBounds ) =
4477
+ range(atVariance(- variance)(reapply(tp.lo)), reapply(tp.hi))
4478
+ tp.argForParam(pre) match {
4479
+ case arg @ TypeRef (pre, _) if pre.isArgPrefixOf(arg.symbol) =>
4480
+ arg.info match {
4481
+ case argInfo : TypeBounds => expandBounds(argInfo)
4482
+ case argInfo => reapply(arg)
4483
+ }
4484
+ case arg : TypeBounds => expandBounds(arg)
4485
+ case arg => reapply(arg)
4486
+ }
4472
4487
}
4473
4488
4474
4489
/** Derived selection.
@@ -4482,9 +4497,12 @@ object Types {
4482
4497
if (tp.symbol.is(ClassTypeParam )) expandParam(tp, preHi)
4483
4498
else tryWiden(tp, preHi)
4484
4499
forwarded.orElse(
4485
- range(super .derivedSelect(tp, preLo), super .derivedSelect(tp, preHi)))
4500
+ range(super .derivedSelect(tp, preLo).loBound , super .derivedSelect(tp, preHi).hiBound ))
4486
4501
case _ =>
4487
- super .derivedSelect(tp, pre)
4502
+ super .derivedSelect(tp, pre) match {
4503
+ case TypeBounds (lo, hi) => range(lo, hi)
4504
+ case tp => tp
4505
+ }
4488
4506
}
4489
4507
4490
4508
override protected def derivedRefinedType (tp : RefinedType , parent : Type , info : Type ): Type =
0 commit comments