Commit 3b974c5
authored
Avoid too eager transform of $outer for lhs & accessor rhs (#18949)
Fix #18927
The transformer in `mapOuter` in `Constructors` was transforming trees
it should not:
```scala
override def transform(tree: Tree)(using Context) = tree match {
[....]
case tree: RefTree if tree.symbol.is(ParamAccessor) && tree.symbol.name == nme.OUTER =>
ref(outerParam)
[...]
```
There were two problems:
- This case transformed LHS of `$outer` assignments in constructors. So, instead of setting the `$outer` field in the current class with the constructor, it was replaced with the $outer of the outer class. That resulted in not assigning any value to the `$outer` in inner class, and double assignment to the val in outer class.
- LHS of the accessor def was also transformed, so it was evaluated to the `$outer` of the outer class.
This only happened when the nested class is created in the secondary constructor, as the primary constructor is not transformed (only the template body)File tree
2 files changed
+19
-0
lines changed- compiler/src/dotty/tools/dotc/transform
- tests/pos
2 files changed
+19
-0
lines changedLines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
197 | 198 | | |
198 | 199 | | |
199 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
200 | 205 | | |
201 | 206 | | |
202 | 207 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
0 commit comments