Skip to content

Commit e5742aa

Browse files
committed
Replace object leak with object non-init error
1 parent 90afb95 commit e5742aa

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

compiler/src/dotty/tools/dotc/transform/init/Errors.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ object Errors {
115115
report.warning(show + stacktrace, objs.head.srcPos)
116116
}
117117

118-
case class ObjectLeakDuringInit(obj: Symbol, trace: Seq[Tree]) extends Error {
118+
case class ObjectNotInit(obj: Symbol, trace: Seq[Tree]) extends Error {
119119
def source: Tree = trace.last
120-
def show(using Context): String = obj.show + " leaked during its initialization " + "."
120+
def show(using Context): String = obj.show + " not yet initialized " + "."
121121

122122
override def issue(using Context): Unit =
123123
report.warning(show + stacktrace, obj.srcPos)

compiler/src/dotty/tools/dotc/transform/init/Objects.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,14 @@ class Objects {
447447
if cycle.nonEmpty then
448448
val classDef = obj.klass.defTree
449449
var trace1 = trace.toVector.dropWhile(_ != classDef) :+ source
450-
val warning =
450+
val warnings =
451451
if cycle.size > 1 then
452-
CyclicObjectInit(cycle, trace1)
452+
CyclicObjectInit(cycle, trace1) :: Nil
453453
else
454-
ObjectLeakDuringInit(obj.klass, trace1)
455-
Result(obj, warning :: Nil)
454+
val o = heap(obj)
455+
if o.fields.contains(obj.klass) then Nil
456+
else ObjectNotInit(obj.klass, trace1) :: Nil
457+
Result(obj, warnings)
456458
else if obj.klass.is(Flags.JavaDefined) then
457459
// Errors will be reported for method calls on it
458460
Result(Bottom, Nil)
@@ -845,6 +847,10 @@ class Objects {
845847
val superCls = superParent.tpe.classSymbol.asClass
846848
initParent(superParent)
847849

850+
// Access to the object possible after this point
851+
if klass.isStaticOwner then
852+
thisV.updateField(klass, thisV)
853+
848854
val parents = tpl.parents.tail
849855
val mixins = klass.baseClasses.tail.takeWhile(_ != superCls)
850856
mixins.reverse.foreach { mixin =>

0 commit comments

Comments
 (0)