Commit 479fd13
committed
Set module class fields to static except bitmap fields
Still we have a problem with the following magic:
https://github.com/scala/scala/pull/7270/files#r221195225
It is a magic for two reasons:
1. It generates `getstatic` for `Select(This(O$), x)`
2. It is not affected by compilation order of classes
For the second, suppose the backend compiles `A$B` before `A`.
Then the class `A$B` does not see that `x` is static,
which should cause problem at runtime:
```
object A {
private[this] val x: Int = 10
class B {
val y = x
}
}
```
The following are the reasons why it works in scalac:
1. inner classes always come after the outer class
2. non `private[this]` fields are accessed via accessor methods, which are not static
3. inside the module class, access to the fields are compiled after setting the static flag
4. the code generation specialize for trees like `Select(This(O$), x)`, where `x` is a static member1 parent 38a5aec commit 479fd13
1 file changed
+8
-3
lines changedLines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
132 | | - | |
| 133 | + | |
| 134 | + | |
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
137 | 139 | | |
138 | | - | |
139 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
140 | 145 | | |
141 | 146 | | |
142 | 147 | | |
| |||
0 commit comments