@@ -406,7 +406,6 @@ class Semantic {
406
406
given Trace = trace1
407
407
val cls = target.owner.enclosingClass.asClass
408
408
val ddef = target.defTree.asInstanceOf [DefDef ]
409
- // try early promotion here; if returns error, returns cold
410
409
val env2 = Env (ddef, args.map(_.value).widenArgs)
411
410
if target.isPrimaryConstructor then
412
411
given Env = env2
@@ -497,6 +496,29 @@ class Semantic {
497
496
Result (value2, errors)
498
497
}
499
498
}
499
+
500
+ def accessLocal (sym : Symbol , default : Result , klass : ClassSymbol , source : Tree ): Contextual [Result ] =
501
+ sym.defTree match {
502
+ case vdef : ValDef =>
503
+ // resolve this for local variable
504
+ val enclosingClass = sym.owner.enclosingClass.asClass
505
+ val thisValue2 = resolveThis(enclosingClass, value, klass, source)
506
+ thisValue2 match {
507
+ case Hot => Result (Hot , Errors .empty)
508
+
509
+ case Cold =>
510
+ val error = AccessCold (sym, source, trace.toVector)
511
+ Result (Hot , error :: Nil )
512
+
513
+ case addr : Addr =>
514
+ val res = eval(vdef.rhs, addr, klass)
515
+ if res.value.promote(" Try promote" , source).isEmpty then Result (Hot , Errors .empty) else res
516
+
517
+ case _ => ???
518
+ }
519
+
520
+ case _ => default
521
+ }
500
522
end extension
501
523
502
524
// ----- Promotion ----------------------------------------------------
@@ -903,26 +925,7 @@ class Semantic {
903
925
// It's always safe to approximate them with `Cold`.
904
926
Result (Cold , Nil )
905
927
else
906
- sym.defTree match {
907
- case vdef : ValDef => {
908
- // resolve this for local variable
909
- val enclosingClass = sym.owner.enclosingClass.asClass
910
- val thisValue2 = resolveThis(enclosingClass, thisV, klass, source)
911
- thisValue2 match {
912
- case Hot => Result (Hot , Errors .empty)
913
- case Cold => {
914
- val error = AccessCold (sym, source, trace.toVector)
915
- Result (Hot , error :: Nil )
916
- }
917
- case addr : Addr => {
918
- val res = eval(vdef.rhs, addr, klass)
919
- if res.value.promote(" Try promote" , source).isEmpty then Result (Hot , Errors .empty) else res
920
- }
921
- case _ => ???
922
- }
923
- }
924
- case _ => default()
925
- }
928
+ thisV.accessLocal(sym, default(), klass, source)
926
929
927
930
case tmref : TermRef =>
928
931
cases(tmref.prefix, thisV, klass, source).select(tmref.symbol, source)
0 commit comments