@@ -52,7 +52,17 @@ object Semantic:
5252 *
5353 */
5454 sealed abstract class Value :
55- def show : String = this .toString()
55+ def show (using Context ): String = this match
56+ case ThisRef (klass) =>
57+ " ThisRef[" + klass.show + " ]"
58+ case Warm (klass, outer, ctor, args) =>
59+ " Warm[" + klass.show + " ] { outer = " + outer.show + " , args = " + args.map(_.show).mkString(" (" , " , " , " )" ) + " }"
60+ case Fun (expr, thisV, klass) =>
61+ " Fun { this = " + thisV.show + " , owner = " + klass.show + " }"
62+ case RefSet (values) =>
63+ values.map(_.show).mkString(" Set { " , " , " , " }" )
64+ case _ =>
65+ this .toString()
5666
5767 def isHot = this == Hot
5868 def isCold = this == Cold
@@ -792,8 +802,11 @@ object Semantic:
792802 else
793803 // no source code available
794804 promoteArgs()
795- val error = CallUnknown (target, trace.toVector)
796- reporter.report(error)
805+ // try promoting the receiver as last resort
806+ val hasErrors = Reporter .hasErrors { ref.promote(" try promote value to hot" ) }
807+ if hasErrors then
808+ val error = CallUnknown (target, trace.toVector)
809+ reporter.report(error)
797810 Hot
798811 else
799812 // method call resolves to a field
@@ -1036,9 +1049,9 @@ object Semantic:
10361049 extension (value : Value )
10371050 /** Promotion of values to hot */
10381051 def promote (msg : String ): Contextual [Unit ] = log(" promoting " + value + " , promoted = " + promoted, printer) {
1039- if promoted.isCurrentObjectPromoted then Nil else
1052+ if ! promoted.isCurrentObjectPromoted then
10401053
1041- value. match
1054+ value match
10421055 case Hot =>
10431056
10441057 case Cold =>
@@ -1099,8 +1112,9 @@ object Semantic:
10991112 */
11001113 def tryPromote (msg : String ): Contextual [List [Error ]] = log(" promote " + warm.show + " , promoted = " + promoted, printer) {
11011114 val classRef = warm.klass.appliedRef
1102- if classRef.memberClasses.nonEmpty || ! warm.isFullyFilled then
1103- return PromoteError (msg, trace.toVector) :: Nil
1115+ val hasInnerClass = classRef.memberClasses.filter(_.symbol.hasSource).nonEmpty
1116+ if hasInnerClass then
1117+ return PromoteError (msg + " Promotion cancelled as the value contains inner classes. " , trace.toVector) :: Nil
11041118
11051119 val errors = Reporter .stopEarly {
11061120 for klass <- warm.klass.baseClasses if klass.hasSource do
@@ -1352,13 +1366,13 @@ object Semantic:
13521366 case Select (qual, _) =>
13531367 eval(qual, thisV, klass)
13541368 val res = eval(rhs, thisV, klass)
1355- extendTrace(rhs ) {
1356- res.ensureHot(" The RHS of reassignment must be fully initialized." )
1369+ extendTrace(expr ) {
1370+ res.ensureHot(" The RHS of reassignment must be fully initialized. Found = " + res.show + " . " )
13571371 }
13581372 case id : Ident =>
13591373 val res = eval(rhs, thisV, klass)
1360- extendTrace(rhs ) {
1361- res.ensureHot(" The RHS of reassignment must be fully initialized." )
1374+ extendTrace(expr ) {
1375+ res.ensureHot(" The RHS of reassignment must be fully initialized. Found = " + res.show + " . " )
13621376 }
13631377
13641378 case closureDef(ddef) =>
0 commit comments