@@ -144,6 +144,8 @@ class Objects(using Context @constructorOnly):
144144
145145 def isObjectRef : Boolean = this .isInstanceOf [ObjectRef ]
146146
147+ def asObjectRef : ObjectRef = this .asInstanceOf [ObjectRef ]
148+
147149 def valValue (sym : Symbol )(using Heap .MutableData ): Value = Heap .readVal(this , sym)
148150
149151 def varValue (sym : Symbol )(using Heap .MutableData ): Value = Heap .readVal(this , sym)
@@ -178,6 +180,12 @@ class Objects(using Context @constructorOnly):
178180
179181 /** A reference to a static object */
180182 case class ObjectRef private (klass : ClassSymbol )(using Trace ) extends Ref :
183+ var afterSuperCall = false
184+
185+ def isAfterSuperCall = afterSuperCall
186+
187+ def setAfterSuperCall (): Unit = afterSuperCall = true
188+
181189 def owner = klass
182190
183191 def show (using Context ) = " ObjectRef(" + klass.show + " )"
@@ -1058,6 +1066,9 @@ class Objects(using Context @constructorOnly):
10581066 else if target.equals(defn.Predef_classOf ) then
10591067 // Predef.classOf is a stub method in tasty and is replaced in backend
10601068 UnknownValue
1069+ else if ref.isInstanceOf [ObjectRef ] && ! ref.asObjectRef.isAfterSuperCall then
1070+ report.warning(" Calling " + target + " of object " + ref.klass + " before the super constructor of the object finishes! " + Trace .show, Trace .position)
1071+ Bottom
10611072 else if target.hasSource then
10621073 val cls = target.owner.enclosingClass.asClass
10631074 val ddef = target.defTree.asInstanceOf [DefDef ]
@@ -2112,6 +2123,10 @@ class Objects(using Context @constructorOnly):
21122123 tasks.foreach(task => task())
21132124 end if
21142125
2126+ if thisV.isInstanceOf [ObjectRef ] && klass == thisV.klass then
2127+ thisV.asObjectRef.setAfterSuperCall()
2128+ end if
2129+
21152130 // class body
21162131 tpl.body.foreach {
21172132 case vdef : ValDef if ! vdef.symbol.is(Flags .Lazy ) && ! vdef.rhs.isEmpty =>
0 commit comments