Skip to content

Commit

Permalink
Fix crash with footprint comput related to local var
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed Aug 23, 2024
1 parent e46f61a commit e388195
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ class Objects(using Context @constructorOnly):
if !visited.contains(value) then
toVisit += value

case objRef: ObjectRef =>
case objRef: ObjectRef if objRef != currentObj =>
// Thanks to initialization-time irrelevance, there is no need to
// visit the heap regions owned by other global objects.
//
Expand Down Expand Up @@ -707,7 +707,7 @@ class Objects(using Context @constructorOnly):
val heapGC =
if cacheResult then Heap.gc(value, footprint, heapAfter, changeSetNew)
else heapAfter
Res(value, heapAfter, changeSetNew)
Res(value, heapGC, changeSetNew)
}
Heap.update(heapBefore ++ result.heap, changeSetBefore ++ result.changeSet)

Expand Down
6 changes: 6 additions & 0 deletions tests/init-global/pos/footprint-local.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object A:
val f = foo()
val a = f()
def foo(): () => Int =
var x = 10
() => x

0 comments on commit e388195

Please sign in to comment.