diff --git a/compiler/src/dotty/tools/dotc/core/tasty/BestEffortTastyWriter.scala b/compiler/src/dotty/tools/dotc/core/tasty/BestEffortTastyWriter.scala index 13a6a274ed96..7a170b5c0cfb 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/BestEffortTastyWriter.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/BestEffortTastyWriter.scala @@ -18,12 +18,13 @@ object BestEffortTastyWriter: unit.pickled.foreach { (clz, binary) => val parts = clz.fullName.mangledString.split('.') val outPath = outputPath(parts.toList, dir) - val outTastyFile = new File(outPath) - val outstream = new DataOutputStream(new PlainFile(outTastyFile).bufferedOutput) + val file = new File(outPath) + val outTastyFile = new PlainFile(file) + val outstream = new DataOutputStream(outTastyFile.bufferedOutput) try outstream.write(binary()) catch case ex: ClosedByInterruptException => try - outTastyFile.delete() // don't leave an empty or half-written tastyfile around after an interrupt + file.delete() // don't leave an empty or half-written tastyfile around after an interrupt catch case _: Throwable => throw ex diff --git a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala index bfa684eef8b4..010114e49864 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala @@ -864,7 +864,7 @@ class Objects(using Context @constructorOnly): Bottom case Bottom => - if field.isStaticObject then ObjectRef(field.moduleClass.asClass) + if field.isStaticObject then accessObject(field.moduleClass.asClass) else Bottom case ValueSet(values) => diff --git a/tests/init-global/warn/cyclic-object.scala b/tests/init-global/warn/cyclic-object.scala new file mode 100644 index 000000000000..e997d3259877 --- /dev/null +++ b/tests/init-global/warn/cyclic-object.scala @@ -0,0 +1,9 @@ +package cyclicObject + +object O1 { // warn + val o = cyclicObject.O2 +} + +object O2 { + val o = cyclicObject.O1 +} diff --git a/tests/init-global/warn/deadlock.scala b/tests/init-global/warn/deadlock.scala new file mode 100644 index 000000000000..d39c572599af --- /dev/null +++ b/tests/init-global/warn/deadlock.scala @@ -0,0 +1,26 @@ +// example of cyclic initialization causing deadlock + +package pkg + +object Main extends App { + val createPredef = new Runnable { def run = { val _ = Predef } } + val createSeq = new Runnable { def run = { val _ = Seq } } + new Thread(createPredef).start() + new Thread(createSeq).start() + Thread.sleep(100) + val seq = Predef.seq + val predef = Seq.predef + println("done") +} + +object Predef { // warn + Thread.sleep(10) + val seq = Seq + println("done Predef") +} + +object Seq { + Thread.sleep(10) + val predef = Predef + println("done Seq") +}