@@ -52,7 +52,17 @@ object Semantic:
52
52
*
53
53
*/
54
54
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()
56
66
57
67
def isHot = this == Hot
58
68
def isCold = this == Cold
@@ -792,8 +802,11 @@ object Semantic:
792
802
else
793
803
// no source code available
794
804
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)
797
810
Hot
798
811
else
799
812
// method call resolves to a field
@@ -1036,9 +1049,9 @@ object Semantic:
1036
1049
extension (value : Value )
1037
1050
/** Promotion of values to hot */
1038
1051
def promote (msg : String ): Contextual [Unit ] = log(" promoting " + value + " , promoted = " + promoted, printer) {
1039
- if promoted.isCurrentObjectPromoted then Nil else
1052
+ if ! promoted.isCurrentObjectPromoted then
1040
1053
1041
- value. match
1054
+ value match
1042
1055
case Hot =>
1043
1056
1044
1057
case Cold =>
@@ -1099,8 +1112,9 @@ object Semantic:
1099
1112
*/
1100
1113
def tryPromote (msg : String ): Contextual [List [Error ]] = log(" promote " + warm.show + " , promoted = " + promoted, printer) {
1101
1114
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
1104
1118
1105
1119
val errors = Reporter .stopEarly {
1106
1120
for klass <- warm.klass.baseClasses if klass.hasSource do
@@ -1352,13 +1366,13 @@ object Semantic:
1352
1366
case Select (qual, _) =>
1353
1367
eval(qual, thisV, klass)
1354
1368
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 + " . " )
1357
1371
}
1358
1372
case id : Ident =>
1359
1373
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 + " . " )
1362
1376
}
1363
1377
1364
1378
case closureDef(ddef) =>
0 commit comments