Skip to content

Commit 632b7d3

Browse files
committed
Disallow non-hot arguments to non-constructors
1 parent 08f040c commit 632b7d3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ class Semantic {
376376
Result(Hot, error :: Nil)
377377

378378
case addr: Addr =>
379+
val isLocal = meth.owner.isClass
379380
val target =
380381
if !needResolve then
381382
meth
@@ -389,12 +390,20 @@ class Semantic {
389390
if target.hasSource then
390391
given Trace = trace1
391392
val cls = target.owner.enclosingClass.asClass
393+
val ddef = target.defTree.asInstanceOf[DefDef]
394+
val env2 = Env(ddef, args.widen)
392395
if target.isPrimaryConstructor then
396+
given Env = env2
393397
val tpl = cls.defTree.asInstanceOf[TypeDef].rhs.asInstanceOf[Template]
394398
eval(tpl, addr, cls, cacheResult = true)
399+
else if target.isConstructor then
400+
given Env = env2
401+
eval(ddef.rhs, addr, cls, cacheResult = true)
395402
else
396-
val rhs = target.defTree.asInstanceOf[ValOrDefDef].rhs
397-
eval(rhs, addr, cls, cacheResult = true)
403+
val errors = args.flatMap { arg => arg.promote("May only use initialized value as arguments", arg.source) }
404+
use(Env.empty) {
405+
eval(ddef.rhs, addr, cls, cacheResult = true)
406+
}
398407
else if addr.canIgnoreMethodCall(target) then
399408
Result(Hot, Nil)
400409
else

0 commit comments

Comments
 (0)