Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-Ysafe-init-global not working with Scala 2 library TASTy #18882

Open
nicolasstucki opened this issue Nov 8, 2023 · 7 comments · Fixed by #19192
Open

-Ysafe-init-global not working with Scala 2 library TASTy #18882

nicolasstucki opened this issue Nov 8, 2023 · 7 comments · Fixed by #19192

Comments

@nicolasstucki
Copy link
Contributor

Problematic tests

  • tests/init-global/neg/patmat.scala
  • tests/init-global/neg/t9312.scala
  • tests/init-global/neg/unapplySeq-implicit-arg.scala
  • tests/init-global/neg/unapplySeq-implicit-arg2.scala
  • tests/init-global/neg/unapplySeq-implicit-arg3.scala

Reproduction 1

sbt> set ThisBuild/Build.useScala2LibraryTasty := true
sbt> scala3-bootstrapped/testCompilation tests/init-global/neg/t9312.scala

Reproduction 2

Without library TASTy
sbt> set ThisBuild/Build.useScala2LibraryTasty := false
sbt> scala3-bootstrapped/scalac -Ysafe-init-global tests/init-global/neg/t9312.scala
-- Warning: tests/init-global/neg/t9312.scala:18:11 ----------------------------
18 |    object Child1 extends Child     // error
   |           ^
   |Cyclic initialization: object Child1 -> object Parent -> object Child1. Calling trace:
   |-> object Child1 extends Child     // error [ t9312.scala:18 ]
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |-> trait Child {    [ t9312.scala:12 ]
   |   ^
   |-> val parent = Parent      [ t9312.scala:14 ]
   |                ^^^^^^
   |-> object Parent {                    // error      [ t9312.scala:11 ]
   |   ^
   |-> final val children = Set(Child1, Child2) [ t9312.scala:21 ]
   |                            ^^^^^^
-- Warning: tests/init-global/neg/t9312.scala:11:9 -----------------------------
11 |  object Parent {                    // error
   |         ^
   |Cyclic initialization: object Parent -> object Child2 -> object Parent. Calling trace:
   |-> object Parent {                    // error      [ t9312.scala:11 ]
   |   ^
   |-> final val children = Set(Child1, Child2) [ t9312.scala:21 ]
   |                                    ^^^^^^
   |-> object Child2 extends Child      [ t9312.scala:19 ]
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |-> trait Child {    [ t9312.scala:12 ]
   |   ^
   |-> val parent = Parent      [ t9312.scala:14 ]
   |                ^^^^^^
2 warnings found
With library TASTy
sbt> set ThisBuild/Build.useScala2LibraryTasty := true
sbt> scala3-bootstrapped/scalac -Ysafe-init-global tests/init-global/neg/t9312.scala
-- Warning: tests/init-global/neg/t9312.scala:18:11 ----------------------------
18 |    object Child1 extends Child     // error
   |           ^
   |Cyclic initialization: object Child1 -> object Parent -> object Child1. Calling trace:
   |-> object Child1 extends Child     // error [ t9312.scala:18 ]
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |-> trait Child {    [ t9312.scala:12 ]
   |   ^
   |-> val parent = Parent      [ t9312.scala:14 ]
   |                ^^^^^^
   |-> object Parent {                    // error      [ t9312.scala:11 ]
   |   ^
   |-> final val children = Set(Child1, Child2) [ t9312.scala:21 ]
   |                            ^^^^^^
-- Warning: tests/init-global/neg/t9312.scala:11:9 -----------------------------
11 |  object Parent {                    // error
   |         ^
   |Cyclic initialization: object Parent -> object Child2 -> object Parent. Calling trace:
   |-> object Parent {                    // error      [ t9312.scala:11 ]
   |   ^
   |-> final val children = Set(Child1, Child2) [ t9312.scala:21 ]
   |                                    ^^^^^^
   |-> object Child2 extends Child      [ t9312.scala:19 ]
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |-> trait Child {    [ t9312.scala:12 ]
   |   ^
   |-> val parent = Parent      [ t9312.scala:14 ]
   |                ^^^^^^
Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.apply(index)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating a field before its initialization: variable mutationCount. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.mutationCount = ArrayBuffer.this.mutationCount.+(1)

Mutating a field before its initialization: variable size0. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.size0 = ArrayBuffer.this.length.+(elemsLength)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating a field before its initialization: variable mutationCount. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.mutationCount = ArrayBuffer.this.mutationCount.+(1)

Mutating a field before its initialization: variable size0. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.size0 = ArrayBuffer.this.length.+(elemsLength)

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.appended[A](element)

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.updated[A](index, element)

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.apply(index)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating a field before its initialization: variable mutationCount. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.mutationCount = ArrayBuffer.this.mutationCount.+(1)

Mutating a field before its initialization: variable size0. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.size0 = ArrayBuffer.this.length.+(elemsLength)

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.appended[A](element)

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.updated[A](index, element)

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.apply(index)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating a field before its initialization: variable mutationCount. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.mutationCount = ArrayBuffer.this.mutationCount.+(1)

Mutating a field before its initialization: variable size0. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.size0 = ArrayBuffer.this.length.+(elemsLength)

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.appended[A](element)

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.updated[A](index, element)

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.apply(index)

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.appended[A](element)

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.updated[A](index, element)

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.apply(index)

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.appended[A](element)

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.updated[A](index, element)

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.apply(index)

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.appended[A](element)

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.updated[A](index, element)

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.apply(index)

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.appended[A](element)

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.updated[A](index, element)

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.apply(index)

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.appended[A](element)

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.updated[A](index, element)

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.clone()

Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.apply(index)

Reading mutable state of object ArrayBuffer during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.apply(n)

Mutating object ArrayBuffer during initialization of object Parent.
Mutating other static objects during the initialization of one static object is forbidden. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> ArrayBuffer.this.array.update(index, elem.asInstanceOf[AnyRef])

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.appended[A](element)

Mutating a field before its initialization: variable content. Calling trace:

-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> hc.content = hc.content.updated[A](index, element)

86 warnings found

Question

What trigers the extra warnings? It is possible that the TASTy has some inconsitent information. It is also possible that the TASTy has more information, for example, now we know which classes have a pure constuctor.

@liufengyun
Copy link
Contributor

I'll take a look at it. Is it a blocker?

@nicolasstucki
Copy link
Contributor Author

Is it a blocker?

Not yet

@nicolasstucki
Copy link
Contributor Author

These ones are also probematic

  • tests/init-global/pos/patmat.scala
  • tests/init-global/pos/patmat-interpolator.scala
  • tests/init-global/pos/unapplySeq-implicit-arg-pos.scala
  • tests/init-global/pos/global-cycle11.scala

liufengyun added a commit to dotty-staging/dotty that referenced this issue Nov 15, 2023
liufengyun added a commit to dotty-staging/dotty that referenced this issue Nov 15, 2023
liufengyun added a commit to dotty-staging/dotty that referenced this issue Nov 15, 2023
liufengyun added a commit to dotty-staging/dotty that referenced this issue Nov 15, 2023
liufengyun added a commit that referenced this issue Nov 17, 2023
…ne numbers (#18930)

Make sure that trace is shown correctly in the presence of invalid line
numbers (-1) in TASTy.

Before:

```Scala
Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace: 
-> object Parent {                    // error  [ t9312.scala:11 ]
   ^
-> final val children = Set(Child1, Child2)     [ t9312.scala:21 ]
                        ^^^^^^^^^^^^^^^^^^^
-> BitmapIndexedSetNode.this.originalHashes.apply(index)
```

After:

```Scala
Reading mutable state of object Array during initialization of object Parent.
Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
├── object Parent {                    // error	[ t9312.scala:11 ]
│      ^
├── final val children = Set(Child1, Child2)	[ t9312.scala:21 ]
│                        ^^^^^^^^^^^^^^^^^^^
├── scala.collection.IterableFactory.apply
├── IterableFactory.this.from[A](elems)
├── scala.collection.immutable.Set.from
├── scala.collection.immutable.Set.newBuilder[E].addAll(it)
├── scala.collection.immutable.SetBuilderImpl.addAll
├── super.addAll(xs)
├── scala.collection.mutable.Growable.addAll
├── Growable.this.addOne(it.next())
├── scala.collection.immutable.SetBuilderImpl.addOne
├── SetBuilderImpl.this.hashSetBuilder.addOne(elem)
├── scala.collection.immutable.HashSetBuilder.addOne
├── HashSetBuilder.this.update(HashSetBuilder.this.rootNode, elem, h, im, 0)
├── scala.collection.immutable.HashSetBuilder.update
├── bm.getHash(index)
├── scala.collection.immutable.BitmapIndexedSetNode.getHash
└── BitmapIndexedSetNode.this.originalHashes.apply(index)
```

 Ref: #18882
@nicolasstucki
Copy link
Contributor Author

nicolasstucki commented Nov 22, 2023

Note that these tests are now blacklisted

To test them on the CI, remove them from the blacklist and use [test_scala2_library_tasty] in the PR message.

See #18892

@liufengyun
Copy link
Contributor

Tried the latest master with

sbt:scala3> set ThisBuild/Build.useScala2LibraryTasty := true
sbt:scala3> scala3-compiler-bootstrapped/scalac -Ysafe-init-global -d out tests/init-global/neg/t9312.scala

And get a crash in loading the TASTy:

TASTy file scala/LowPriorityImplicits.tasty is broken, reading aborted with class java.lang.ArrayIndexOutOfBoundsException
  Index 6583 out of bounds for length 6583
Exception in thread "main" java.io.IOException: TASTy file scala/$less$colon$less.tasty is broken, reading aborted with class java.lang.ArrayIndexOutOfBoundsException
  Index 9345 out of bounds for length 9345
	at dotty.tools.dotc.core.TastyLoader.handleUnpicklingExceptions(SymbolLoaders.scala:448)
	at dotty.tools.dotc.core.TastyLoader.<init>(SymbolLoaders.scala:423)
	at dotty.tools.dotc.config.JavaPlatform.newTastyLoader(JavaPlatform.scala:71)
	at dotty.tools.dotc.core.SymbolLoaders$.initializeFromClassPath(SymbolLoaders.scala:201)
	at dotty.tools.dotc.core.SymbolLoaders$PackageLoader.enterClasses$$anonfun$1(SymbolLoaders.scala:276)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.VectorStatics$.foreachRec(Vector.scala:2124)
	at scala.collection.immutable.Vector.foreach(Vector.scala:2130)
	at dotty.tools.dotc.core.SymbolLoaders$PackageLoader.enterClasses(SymbolLoaders.scala:276)
	at dotty.tools.dotc.core.SymbolLoaders$PackageLoader.doComplete$$anonfun$1$$anonfun$1(SymbolLoaders.scala:295)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at dotty.tools.dotc.core.SymbolLoaders$PackageLoader$PackageScope.lookupEntry(SymbolLoaders.scala:236)
	at dotty.tools.dotc.core.SymDenotations$PackageClassDenotation.proceedWithEnter(SymDenotations.scala:2575)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.enter(SymDenotations.scala:2049)
	at dotty.tools.dotc.core.Symbols$Symbol.entered(Symbols.scala:210)
	at dotty.tools.dotc.core.Definitions.enterSpecialPolyClass(Definitions.scala:88)
	at dotty.tools.dotc.core.Definitions.RepeatedParamClass(Definitions.scala:640)
	at dotty.tools.dotc.core.Definitions.syntheticScalaClasses(Definitions.scala:2133)
	at dotty.tools.dotc.core.Definitions.syntheticCoreClasses(Definitions.scala:2141)
	at dotty.tools.dotc.core.Definitions.init(Definitions.scala:2157)
	at dotty.tools.dotc.core.Contexts$ContextBase.initialize(Contexts.scala:902)
	at dotty.tools.dotc.core.Contexts$Context.initialize(Contexts.scala:523)
	at dotty.tools.dotc.Run.rootContext(Run.scala:450)
	at dotty.tools.dotc.Run.<init>(Run.scala:471)
	at dotty.tools.dotc.Compiler.newRun(Compiler.scala:172)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
	at dotty.tools.dotc.Driver.process(Driver.scala:197)
	at dotty.tools.dotc.Driver.process(Driver.scala:165)
	at dotty.tools.dotc.Driver.process(Driver.scala:177)
	at dotty.tools.dotc.Driver.main(Driver.scala:207)
	at dotty.tools.dotc.Main.main(Main.scala)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 9345 out of bounds for length 9345
	at dotty.tools.tasty.TastyReader.readLongNat(TastyReader.scala:78)
	at dotty.tools.tasty.TastyReader.readNat(TastyReader.scala:64)
	at dotty.tools.tasty.TastyReader.readNameRef(TastyReader.scala:118)
	at dotty.tools.dotc.core.tasty.AttributeUnpickler.attributes$lzyINIT1(AttributeUnpickler.scala:24)
	at dotty.tools.dotc.core.tasty.AttributeUnpickler.attributes(AttributeUnpickler.scala:14)
	at dotty.tools.dotc.core.tasty.DottyUnpickler.$init$$$anonfun$1(DottyUnpickler.scala:61)
	at scala.Option.map(Option.scala:242)
	at dotty.tools.dotc.core.tasty.DottyUnpickler.<init>(DottyUnpickler.scala:61)
	at dotty.tools.dotc.core.TastyLoader.$init$$$anonfun$1(SymbolLoaders.scala:423)
	at dotty.tools.dotc.core.TastyLoader.handleUnpicklingExceptions(SymbolLoaders.scala:439)
	... 32 more

It didn't happen in the previous reproduction of issue. Not sure if something has changed in between. Any ideas? /cc: @nicolasstucki

@nicolasstucki
Copy link
Contributor Author

@liufengyun clean your build. This is due to some additions to the TASTy attribute sections.

@olhotak
Copy link
Contributor

olhotak commented Jan 26, 2024

The sbt command has changed to set ThisBuild/Build.scala2Library := Build.Scala2LibraryTasty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants