Skip to content

Commit e767d6c

Browse files
committed
Sharpen range approximation also for non-class type constructors
1 parent 783785f commit e767d6c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5948,8 +5948,6 @@ object Types {
59485948
if (distributeArgs(args, tp.tyconTypeParams))
59495949
range(tp.derivedAppliedType(tycon, loBuf.toList),
59505950
tp.derivedAppliedType(tycon, hiBuf.toList))
5951-
else if tycon.isLambdaSub || args.exists(isRangeOfNonTermTypes) then
5952-
range(defn.NothingType, defn.AnyType)
59535951
else if ctx.phase == Phases.checkCapturesPhase && args.forall(differsOnlyInCaptureSet) then
59545952
// This is a stopgap to avoid approximating the core type to Nothing. It can probably be
59555953
// dropped once we capture set ranges that we can keep as inference results.
@@ -5968,6 +5966,8 @@ object Types {
59685966
// We don't have that abstraction yet, so for now we approximate by the bounds, which
59695967
// avoids the failures, even though its soundness status is currently unclear.
59705968
tp.derivedAppliedType(tycon, args.map(rangeToBounds))
5969+
else if tycon.isLambdaSub || args.exists(isRangeOfNonTermTypes) then
5970+
range(defn.NothingType, defn.AnyType)
59715971
else
59725972
// See lampepfl/dotty#14152
59735973
range(defn.NothingType, tp.derivedAppliedType(tycon, args.map(rangeToBounds)))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Name
2+
class TermName extends Name
3+
class TypeName extends Name
4+
5+
trait ParamInfo:
6+
type ThisName <: Name
7+
def variance: Long
8+
object ParamInfo:
9+
type Of[N <: Name] = ParamInfo { type ThisName = N }
10+
11+
def test(tparams1: List[ParamInfo{ type ThisName = TypeName }], tparams2: List[ParamInfo.Of[TypeName]]) =
12+
tparams1.lazyZip(tparams2).map((p1, p2) => p1.variance + p2.variance)
13+

0 commit comments

Comments
 (0)