From e3881954204fe8f534fa47643b20122a64ad65db Mon Sep 17 00:00:00 2001 From: Fengyun Liu Date: Fri, 23 Aug 2024 17:22:42 +0200 Subject: [PATCH] Fix crash with footprint comput related to local var --- compiler/src/dotty/tools/dotc/transform/init/Objects.scala | 4 ++-- tests/init-global/pos/footprint-local.scala | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tests/init-global/pos/footprint-local.scala diff --git a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala index 3ecb33972d53..96d03bdaf8de 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala @@ -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. // @@ -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) diff --git a/tests/init-global/pos/footprint-local.scala b/tests/init-global/pos/footprint-local.scala new file mode 100644 index 000000000000..954984662eeb --- /dev/null +++ b/tests/init-global/pos/footprint-local.scala @@ -0,0 +1,6 @@ +object A: + val f = foo() + val a = f() + def foo(): () => Int = + var x = 10 + () => x