Commit 738d75d
committed
fix etorreborre#757
maybe scala/scala#7270 ?
```
package example
import scala.reflect.NameTransformer
object A{
Main.a = 1
}
object B{
Main.b = 1
}
object Main {
var a: Int = 0
var b: Int = 0
def initializeByConstructor(): Int = {
this.a = 0
val List(constructor) = Class.forName("example.A$").getDeclaredConstructors.toList
constructor.setAccessible(true)
constructor.newInstance()
val result = Main.a
this.a = 0
result
}
def initializeByMODULE_field(): Int = {
this.b = 0
Class.forName("example.B$").getDeclaredField(NameTransformer.MODULE_INSTANCE_NAME).get(null)
val result = Main.b
this.b = 0
result
}
def main(args: Array[String]): Unit = {
println((A, B))
println(scala.util.Properties.versionString)
println(initializeByConstructor())
println(initializeByMODULE_field())
}
}
```
```
[info] version 2.12.11
[info] 1
[info] 0
```
```
[info] version 2.13.2
[info] 0
[info] 0
```1 parent 05700d6 commit 738d75d
1 file changed
+8
-4
lines changedLines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | | - | |
75 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
| |||
0 commit comments