Skip to content

Commit e0fc3c2

Browse files
committed
Fix #11464: avoid leaking Range
Using `Range` creates issues of avoid leaking `Range` outside of type approximation. It's better to eliminate `LazyRef` without resorting to `Range`.
1 parent 4f6d6f0 commit e0fc3c2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,9 @@ object TypeOps:
439439
val lo1 = apply(lo)
440440
if (lo1 ne lo) lo1 else tp
441441
case tp: LazyRef if isExpandingBounds =>
442-
emptyRange
442+
if variance == 1 then defn.AnyType
443+
else if variance == -1 then defn.NothingType
444+
else TypeBounds.empty
443445
case _ =>
444446
mapOver(tp)
445447
}

tests/pos/i11464.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trait Txn[T <: Txn[T]]
2+
3+
trait Adjunct
4+
5+
trait Type0
6+
trait Type[A1, Repr[~ <: Txn[~]] <: Expr[~, A1]] extends Type0
7+
8+
object Expr {
9+
def test(peer: Type0): Adjunct = {
10+
new AdjunctImpl(peer.asInstanceOf[Type[Any, ({ type R[~ <: Txn[~]] <: Expr[~, Any] }) # R]])
11+
}
12+
}
13+
14+
trait Expr[T <: Txn[T], +A]
15+
16+
class AdjunctImpl[A, E[~ <: Txn[~]] <: Expr[~, A]](tpe: Type[A, E]) extends Adjunct

0 commit comments

Comments
 (0)