Skip to content

Commit 630fab3

Browse files
committed
Promote fields more eagerly upon initialization
1 parent 7026f8f commit 630fab3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,9 +1036,9 @@ object Semantic:
10361036
extension (value: Value)
10371037
/** Promotion of values to hot */
10381038
def promote(msg: String): Contextual[Unit] = log("promoting " + value + ", promoted = " + promoted, printer) {
1039-
if promoted.isCurrentObjectPromoted then Nil else
1039+
if !promoted.isCurrentObjectPromoted then
10401040

1041-
value.match
1041+
value match
10421042
case Hot =>
10431043

10441044
case Cold =>
@@ -1099,8 +1099,9 @@ object Semantic:
10991099
*/
11001100
def tryPromote(msg: String): Contextual[List[Error]] = log("promote " + warm.show + ", promoted = " + promoted, printer) {
11011101
val classRef = warm.klass.appliedRef
1102-
if classRef.memberClasses.nonEmpty || !warm.isFullyFilled then
1103-
return PromoteError(msg, trace.toVector) :: Nil
1102+
val hasInnerClass = classRef.memberClasses.filter(_.symbol.hasSource).nonEmpty
1103+
if hasInnerClass then
1104+
return PromoteError(msg + "Promotion cancelled as the value contains inner classes. ", trace.toVector) :: Nil
11041105

11051106
val errors = Reporter.stopEarly {
11061107
for klass <- warm.klass.baseClasses if klass.hasSource do
@@ -1635,7 +1636,8 @@ object Semantic:
16351636
if thisV.isThisRef || !thisV.asInstanceOf[Warm].isPopulatingParams then tpl.body.foreach {
16361637
case vdef : ValDef if !vdef.symbol.is(Flags.Lazy) && !vdef.rhs.isEmpty =>
16371638
val res = eval(vdef.rhs, thisV, klass)
1638-
thisV.updateField(vdef.symbol, res)
1639+
val hasErrors = Reporter.hasErrors { res.promote("try promote value to hot") }
1640+
thisV.updateField(vdef.symbol, if hasErrors then res else Hot)
16391641
fieldsChanged = true
16401642

16411643
case _: MemberDef =>

0 commit comments

Comments
 (0)