Skip to content

Commit 19510ca

Browse files
authored
Update Types.scala
Support trivial ranges in ApproximatingTypeMap.distributeArgs Currently, `distributeArgs` immediately returns `false` for invariant type parameters when encountering a `Range` argument. However, nothing currently prevents trivial ranges from being constructed (see `paramInstances`). In these cases, the range effectively represents a precise type.
1 parent c82b623 commit 19510ca

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6796,13 +6796,19 @@ object Types extends TypeUtils {
67966796
// non-range arguments L1, ..., Ln and H1, ..., Hn such that
67976797
// C[L1, ..., Ln] <: C[H1, ..., Hn] by taking the right limits of
67986798
// ranges that appear in as co- or contravariant arguments.
6799-
// Fail for non-variant argument ranges (see use-site else branch below).
6800-
// If successful, the L-arguments are in loBut, the H-arguments in hiBuf.
6799+
// Fail for non-trivial non-variant argument ranges (see use-site else branch below).
6800+
// If successful, the L-arguments are in loBuf, the H-arguments in hiBuf.
68016801
// @return operation succeeded for all arguments.
68026802
def distributeArgs(args: List[Type], tparams: List[ParamInfo]): Boolean = args match {
68036803
case Range(lo, hi) :: args1 =>
68046804
val v = tparams.head.paramVarianceSign
6805-
if (v == 0) false
6805+
if (v == 0) {
6806+
if (lo == hi) {
6807+
loBuf += lo; hiBuf += hi
6808+
distributeArgs(args1, tparams.tail)
6809+
}
6810+
else false
6811+
}
68066812
else {
68076813
if (v > 0) { loBuf += lo; hiBuf += hi }
68086814
else { loBuf += hi; hiBuf += lo }

0 commit comments

Comments
 (0)