Skip to content

Commit

Permalink
Fix bug in init checker while compiling scodec-bits community project
Browse files Browse the repository at this point in the history
  • Loading branch information
q-ata committed Sep 11, 2024
1 parent 614170f commit 1e6111d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
17 changes: 17 additions & 0 deletions tests/init-global/pos/scodec-bits.scala
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 1e6111d

Please sign in to comment.