From 1e6111de81cde91c6862332981c78ac0f9be76f7 Mon Sep 17 00:00:00 2001 From: David Hua Date: Wed, 11 Sep 2024 01:14:54 -0400 Subject: [PATCH 1/2] Fix bug in init checker while compiling scodec-bits community project --- .../tools/dotc/transform/init/Objects.scala | 3 +++ tests/init-global/pos/scodec-bits.scala | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/init-global/pos/scodec-bits.scala 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 From 42981997f37528c01d1658d8213c8212891ee6b0 Mon Sep 17 00:00:00 2001 From: David Hua Date: Wed, 11 Sep 2024 16:09:48 -0400 Subject: [PATCH 2/2] Empty commit to trigger CI