diff --git a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala index 691e67e228ef..52760cf8b6c7 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala @@ -523,6 +523,8 @@ class Objects(using Context @constructorOnly): def getHeapData()(using mutable: MutableData): Data = mutable.heap + def setHeap(newHeap: Data)(using mutable: MutableData): Unit = mutable.heap = newHeap + /** Cache used to terminate the check */ object Cache: case class Config(thisV: Value, env: Env.Data, heap: Heap.Data) @@ -538,6 +540,7 @@ class Objects(using Context @constructorOnly): val result = super.cachedEval(config, expr, cacheResult, default = Res(Bottom, Heap.getHeapData())) { expr => Res(fun(expr), Heap.getHeapData()) } + Heap.setHeap(result.heap) result.value end Cache diff --git a/tests/init-global/pos/scodec-bits.scala b/tests/init-global/pos/scodec-bits.scala new file mode 100644 index 000000000000..97a4a793a4a6 --- /dev/null +++ b/tests/init-global/pos/scodec-bits.scala @@ -0,0 +1,17 @@ +abstract class A { + def a: Long +} + +object O { + case class B() extends A { + def a = 5L + } + case class C(a2: A) extends A { + var c: Long = a2.a + def a = c + } + def f(a: A): A = C(f(a)) + def g(): A = f(B()) + + val x = g() +} \ No newline at end of file