Skip to content

Commit 38ee06e

Browse files
authored
Fix crash in global object initialization checker when select target has no source (#18627)
This fixes a bug in the global object initialization checker that results in a crash that occurs when building the `akka` community project with `-Ysafe-init-global` flag.
2 parents 09ea77e + ea8d6d9 commit 38ee06e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,11 @@ object Objects:
766766
val target = if needResolve then resolve(ref.klass, field) else field
767767
if target.is(Flags.Lazy) then
768768
given Env.Data = Env.emptyEnv(target.owner.asInstanceOf[ClassSymbol].primaryConstructor)
769-
val rhs = target.defTree.asInstanceOf[ValDef].rhs
770-
eval(rhs, ref, target.owner.asClass, cacheResult = true)
769+
if target.hasSource then
770+
val rhs = target.defTree.asInstanceOf[ValDef].rhs
771+
eval(rhs, ref, target.owner.asClass, cacheResult = true)
772+
else
773+
Bottom
771774
else if target.exists then
772775
if target.isOneOf(Flags.Mutable) then
773776
if ref.hasVar(target) then

0 commit comments

Comments
 (0)