Skip to content

Commit 45ed193

Browse files
committed
Evaluate local variable during access
1 parent 8cf4c73 commit 45ed193

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
@@ -694,27 +694,8 @@ class Semantic {
694694
}
695695

696696
/** Evaluate a list of expressions */
697-
def eval(exprs: List[Tree], thisV: Addr, klass: ClassSymbol): Contextual[(List[Result], Env)] = exprs match {
698-
case Nil => (Nil, env)
699-
case h :: t => h match {
700-
case v: ValDef => {
701-
val res = eval(h, thisV, klass)
702-
val newEnv =
703-
if res.value.promote("Try early promotion", h).isEmpty then Env(Map(v.symbol -> Hot)) else Env(Map(v.symbol -> res.value))
704-
withEnv(env.union(newEnv)) {
705-
val (res2, env2) = eval(t, thisV, klass)
706-
(res :: res2, env2)
707-
}
708-
}
709-
case _ => {
710-
val res = eval(h, thisV, klass)
711-
withEnv(env) {
712-
val (res2, env2) = eval(t, thisV, klass)
713-
(res :: res2, env2)
714-
}
715-
}
716-
}
717-
}
697+
def eval(exprs: List[Tree], thisV: Addr, klass: ClassSymbol): Contextual[List[Result]] =
698+
exprs.map { expr => eval(expr, thisV, klass) }
718699

719700
/** Evaluate arguments of methods */
720701
def evalArgs(args: List[Arg], thisV: Addr, klass: ClassSymbol): Contextual[(List[Error], List[ArgInfo])] =
@@ -878,7 +859,7 @@ class Semantic {
878859
case vdef : ValDef =>
879860
// local val definition
880861
// TODO: support explicit @cold annotation for local definitions
881-
eval(vdef.rhs, thisV, klass)
862+
eval(vdef.rhs, thisV, klass, true)
882863
// .ensureHot("Local definitions may only hold initialized values", vdef)
883864

884865
case ddef : DefDef =>
@@ -924,7 +905,9 @@ class Semantic {
924905
// It's always safe to approximate them with `Cold`.
925906
Result(Cold, Nil)
926907
else
927-
Result(env.getOrElse(sym, Hot), Nil)
908+
// resolve this for local variable
909+
val enclosingClass = sym.owner.enclosingClass.asClass
910+
val thisValue2 = resolveThis(enclosingClass, thisV, klass, source)
928911

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

0 commit comments

Comments
 (0)