Skip to content

Commit 30da597

Browse files
authored
Merge pull request #12711 from dotty-staging/leak-ctor
Support leak non-hot values to constructors
2 parents 07f949a + 7fde75e commit 30da597

22 files changed

+611
-148
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ class Checker extends MiniPhase {
4848
if (instantiable && cls.enclosingPackageClass != defn.StdLibPatchesPackage.moduleClass) {
4949
import semantic._
5050
val tpl = tree.rhs.asInstanceOf[Template]
51-
val thisRef = ThisRef(cls)
52-
val obj = Objekt(cls, fields = mutable.Map.empty, outers = mutable.Map(cls -> Hot))
51+
val thisRef = ThisRef(cls).ensureExists
52+
53+
val paramValues = tpl.constr.termParamss.flatten.map(param => param.symbol -> Hot).toMap
54+
5355
given Promoted = Promoted.empty
5456
given Trace = Trace.empty
55-
heap.update(thisRef, obj)
57+
given Env = Env(paramValues)
58+
5659
val res = eval(tpl, thisRef, cls)
5760
res.errors.foreach(_.issue)
5861
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ object Errors {
6969

7070
/** Promote `this` under initialization to fully-initialized */
7171
case class PromoteError(msg: String, source: Tree, trace: Seq[Tree]) extends Error {
72-
def show(using Context): String = "Promote the value under initialization to fully-initialized. " + msg
72+
def show(using Context): String = "Promote the value under initialization to fully-initialized. " + msg + "."
7373
}
7474

7575
case class AccessCold(field: Symbol, source: Tree, trace: Seq[Tree]) extends Error {
7676
def show(using Context): String =
77-
"Access field " + source.show + " on a value with an unknown initialization status" + "."
77+
"Access field " + source.show + " on a value with an unknown initialization status."
7878
}
7979

8080
case class CallCold(meth: Symbol, source: Tree, trace: Seq[Tree]) extends Error {

0 commit comments

Comments
 (0)