Skip to content

Commit f661681

Browse files
committed
Trial 3: don't follow LazyRef in expanding bounds
1 parent 9d1257e commit f661681

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ object TypeOps:
438438
tp.origin, fromBelow = variance > 0 || variance == 0 && tp.hasLowerBound)(using mapCtx)
439439
val lo1 = apply(lo)
440440
if (lo1 ne lo) lo1 else tp
441-
case tp: LazyRef =>
442-
TypeBounds.empty
441+
case tp: LazyRef if isExpandingBounds =>
442+
emptyRange
443443
case _ =>
444444
mapOver(tp)
445445
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5328,8 +5328,23 @@ object Types {
53285328
case _ => tp
53295329
}
53305330

5331+
private var expandingBounds: Boolean = false
5332+
5333+
/** Whether it is currently expanding bounds
5334+
*
5335+
* It is used to avoid following LazyRef in F-Bounds
5336+
*/
5337+
def isExpandingBounds: Boolean = expandingBounds
5338+
53315339
protected def expandBounds(tp: TypeBounds): Type =
5332-
range(atVariance(-variance)(reapply(tp.lo)), reapply(tp.hi))
5340+
if expandingBounds then tp
5341+
else {
5342+
val saved = expandingBounds
5343+
expandingBounds = true
5344+
val res = range(atVariance(-variance)(reapply(tp.lo)), reapply(tp.hi))
5345+
expandingBounds = saved
5346+
res
5347+
}
53335348

53345349
/** Try to widen a named type to its info relative to given prefix `pre`, where possible.
53355350
* The possible cases are listed inline in the code.

0 commit comments

Comments
 (0)