Skip to content

Commit

Permalink
Fix crash in global object initialization checker when select target …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
olhotak authored Oct 2, 2023
2 parents 09ea77e + ea8d6d9 commit 38ee06e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,11 @@ object Objects:
val target = if needResolve then resolve(ref.klass, field) else field
if target.is(Flags.Lazy) then
given Env.Data = Env.emptyEnv(target.owner.asInstanceOf[ClassSymbol].primaryConstructor)
val rhs = target.defTree.asInstanceOf[ValDef].rhs
eval(rhs, ref, target.owner.asClass, cacheResult = true)
if target.hasSource then
val rhs = target.defTree.asInstanceOf[ValDef].rhs
eval(rhs, ref, target.owner.asClass, cacheResult = true)
else
Bottom
else if target.exists then
if target.isOneOf(Flags.Mutable) then
if ref.hasVar(target) then
Expand Down

0 comments on commit 38ee06e

Please sign in to comment.