Skip to content

Commit

Permalink
Disallow non-hot arguments to non-constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed Jun 9, 2021
1 parent 08f040c commit 632b7d3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/init/Semantic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ class Semantic {
Result(Hot, error :: Nil)

case addr: Addr =>
val isLocal = meth.owner.isClass
val target =
if !needResolve then
meth
Expand All @@ -389,12 +390,20 @@ class Semantic {
if target.hasSource then
given Trace = trace1
val cls = target.owner.enclosingClass.asClass
val ddef = target.defTree.asInstanceOf[DefDef]
val env2 = Env(ddef, args.widen)
if target.isPrimaryConstructor then
given Env = env2
val tpl = cls.defTree.asInstanceOf[TypeDef].rhs.asInstanceOf[Template]
eval(tpl, addr, cls, cacheResult = true)
else if target.isConstructor then
given Env = env2
eval(ddef.rhs, addr, cls, cacheResult = true)
else
val rhs = target.defTree.asInstanceOf[ValOrDefDef].rhs
eval(rhs, addr, cls, cacheResult = true)
val errors = args.flatMap { arg => arg.promote("May only use initialized value as arguments", arg.source) }
use(Env.empty) {
eval(ddef.rhs, addr, cls, cacheResult = true)
}
else if addr.canIgnoreMethodCall(target) then
Result(Hot, Nil)
else
Expand Down

0 comments on commit 632b7d3

Please sign in to comment.