Skip to content

Commit

Permalink
Address review: factor out isByNameParam
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed May 27, 2023
1 parent d6629e8 commit 8951bc0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,6 @@ object Objects:
if ctor.isPrimaryConstructor then
val tpl = cls.defTree.asInstanceOf[TypeDef].rhs.asInstanceOf[Template]
extendTrace(cls.defTree) { eval(tpl, ref, cls, cacheResult = true) }
ref
else
extendTrace(ddef) { eval(ddef.rhs, ref, cls, cacheResult = true) }
else
Expand Down Expand Up @@ -817,6 +816,7 @@ object Objects:
* @param sym The symbol of the variable.
*/
def readLocal(thisV: Value, sym: Symbol): Contextual[Value] = log("reading local " + sym.show, printer, (_: Value).show) {
def isByNameParam(sym: Symbol) = sym.is(Flags.Param) && sym.info.isInstanceOf[ExprType]
Env.resolveEnv(sym.enclosingMethod, thisV, summon[Env.Data]) match
case Some(thisV -> env) =>
if sym.is(Flags.Mutable) then
Expand All @@ -837,7 +837,7 @@ object Objects:
try
// Assume forward reference check is doing a good job
val value = Env.valValue(sym)
if sym.is(Flags.Param) && sym.info.isInstanceOf[ExprType] then
if isByNameParam(sym) then
value match
case fun: Fun =>
given Env.Data = fun.env
Expand All @@ -856,7 +856,7 @@ object Objects:
Bottom

case _ =>
if sym.is(Flags.Param) && sym.info.isInstanceOf[ExprType] then
if isByNameParam(sym) then
report.warning("Calling cold by-name alias. Call trace: \n" + Trace.show, Trace.position)
Bottom
else
Expand Down Expand Up @@ -1089,10 +1089,10 @@ object Objects:
eval(expr, thisV, klass)

case Try(block, cases, finalizer) =>
eval(block, thisV, klass)
val res = evalExprs(block :: cases.map(_.body), thisV, klass).join
if !finalizer.isEmpty then
eval(finalizer, thisV, klass)
evalExprs(cases.map(_.body), thisV, klass).join
res

case SeqLiteral(elems, elemtpt) =>
evalExprs(elems, thisV, klass).join
Expand Down

0 comments on commit 8951bc0

Please sign in to comment.