Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in init checker while compiling scodec-bits community project #21574

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}