Skip to content

Commit 0f1586d

Browse files
committed
Evaluate local variable during access
1 parent 2560f15 commit 0f1586d

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

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

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -685,27 +685,8 @@ class Semantic {
685685
}
686686

687687
/** Evaluate a list of expressions */
688-
def eval(exprs: List[Tree], thisV: Addr, klass: ClassSymbol): Contextual[(List[Result], Env)] = exprs match {
689-
case Nil => (Nil, env)
690-
case h :: t => h match {
691-
case v: ValDef => {
692-
val res = eval(h, thisV, klass)
693-
val newEnv =
694-
if res.value.promote("Try early promotion", h).isEmpty then Env(Map(v.symbol -> Hot)) else Env(Map(v.symbol -> res.value))
695-
withEnv(env.union(newEnv)) {
696-
val (res2, env2) = eval(t, thisV, klass)
697-
(res :: res2, env2)
698-
}
699-
}
700-
case _ => {
701-
val res = eval(h, thisV, klass)
702-
withEnv(env) {
703-
val (res2, env2) = eval(t, thisV, klass)
704-
(res :: res2, env2)
705-
}
706-
}
707-
}
708-
}
688+
def eval(exprs: List[Tree], thisV: Addr, klass: ClassSymbol): Contextual[List[Result]] =
689+
exprs.map { expr => eval(expr, thisV, klass) }
709690

710691
/** Evaluate arguments of methods */
711692
def evalArgs(args: List[Arg], thisV: Addr, klass: ClassSymbol): Contextual[(List[Error], List[ArgInfo])] =
@@ -869,7 +850,7 @@ class Semantic {
869850
case vdef : ValDef =>
870851
// local val definition
871852
// TODO: support explicit @cold annotation for local definitions
872-
eval(vdef.rhs, thisV, klass)
853+
eval(vdef.rhs, thisV, klass, true)
873854
// .ensureHot("Local definitions may only hold initialized values", vdef)
874855

875856
case ddef : DefDef =>
@@ -915,7 +896,9 @@ class Semantic {
915896
// It's always safe to approximate them with `Cold`.
916897
Result(Cold, Nil)
917898
else
918-
Result(env.getOrElse(sym, Hot), Nil)
899+
// resolve this for local variable
900+
val enclosingClass = sym.owner.enclosingClass.asClass
901+
val thisValue2 = resolveThis(enclosingClass, thisV, klass, source)
919902

920903
case tmref: TermRef =>
921904
cases(tmref.prefix, thisV, klass, source).select(tmref.symbol, source)

0 commit comments

Comments
 (0)