Skip to content

Commit

Permalink
analyze object when selecting from package (#21511)
Browse files Browse the repository at this point in the history
This PR is an updated version of #20424, which fixes a bug in the global
initialization checker such that when accessing global object through
full path, the checker immediately analyzes the initialization code of
the corresponding object.

[test_scala2_library_tasty]
  • Loading branch information
olhotak authored Sep 3, 2024
2 parents 5fa69ad + 3416509 commit 0e17117
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ class Objects(using Context @constructorOnly):
Bottom

case Bottom =>
if field.isStaticObject then ObjectRef(field.moduleClass.asClass)
if field.isStaticObject then accessObject(field.moduleClass.asClass)
else Bottom

case ValueSet(values) =>
Expand Down
13 changes: 13 additions & 0 deletions compiler/test/dotc/neg-init-global-scala2-library-tasty.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@ unapplySeq-implicit-arg.scala
unapplySeq-implicit-arg2.scala
unapplySeq-implicit-arg3.scala
ScalaCheck.scala
mutable-read8.scala
TypeCast.scala
global-cycle8.scala
global-cycle6.scala
i12544b.scala
t9360.scala
mutable-array.scala
patmat-unapplySeq2.scala
line-spacing.scala
global-list.scala
t5366.scala
mutable-read7.scala
t9115.scala
9 changes: 9 additions & 0 deletions tests/init-global/warn/cyclic-object.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cyclicObject

object O1 { // warn
val o = cyclicObject.O2
}

object O2 {
val o = cyclicObject.O1
}

0 comments on commit 0e17117

Please sign in to comment.