Commit 956121d
committed
Mixin fields with trait setters shouldn't be JVM final
Before:
```
scala> trait T { val foo = 24 }; class C extends T
defined trait T
defined class C
scala> :javap -private -c C
Compiled from "<console>"
public class $line3.$read$$iw$$iw$C implements $line3.$read$$iw$$iw$T {
private final int foo;
public int foo();
Code:
0: aload_0
1: getfield #21 // Field foo:I
4: ireturn
public void $line3$$read$$iw$$iw$T$_setter_$foo_$eq(int);
Code:
0: aload_0
1: iload_1
2: putfield #21 // Field foo:I
5: return
public $line3.$read$$iw$$iw$C();
Code:
0: aload_0
1: invokespecial #30 // Method java/lang/Object."<init>":()V
4: aload_0
5: invokestatic #34 // InterfaceMethod $line3/$read$$iw$$iw$T.$init$:(L$line3/$read$$iw$$iw$T;)V
8: return
}
```
The assignment to the final field `foo` has always contravened the JVM spec,
and this rule is enforced for any classfiles of format 53 and higher.
After this patch:
```
scala> trait T { val foo = 24 }; class C extends T
defined trait T
defined class C
scala> :javap -private -c C
Compiled from "<console>"
public class $line3.$read$$iw$$iw$C implements $line3.$read$$iw$$iw$T {
private int foo;
public int foo();
Code:
0: aload_0
1: getfield #21 // Field foo:I
4: ireturn
public void $line3$$read$$iw$$iw$T$_setter_$foo_$eq(int);
Code:
0: aload_0
1: iload_1
2: putfield #21 // Field foo:I
5: return
public $line3.$read$$iw$$iw$C();
Code:
0: aload_0
1: invokespecial #30 // Method java/lang/Object."<init>":()V
4: aload_0
5: invokestatic #34 // InterfaceMethod $line3/$read$$iw$$iw$T.$init$:(L$line3/$read$$iw$$iw$T;)V
8: getstatic #40 // Field scala/runtime/ScalaRunTime$.MODULE$:Lscala/runtime/ScalaRunTime$;
11: invokevirtual #43 // Method scala/runtime/ScalaRunTime$.releaseFence:()V
14: return
}
```1 parent 7505d9f commit 956121d
File tree
4 files changed
+20
-6
lines changed- src
- compiler/scala/tools/nsc/transform
- reflect/scala/reflect/internal
4 files changed
+20
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
756 | 756 | | |
757 | 757 | | |
758 | 758 | | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
759 | 764 | | |
760 | 765 | | |
761 | 766 | | |
762 | 767 | | |
763 | | - | |
| 768 | + | |
764 | 769 | | |
765 | 770 | | |
766 | 771 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
423 | 423 | | |
424 | 424 | | |
425 | 425 | | |
426 | | - | |
| 426 | + | |
427 | 427 | | |
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
431 | | - | |
| 431 | + | |
432 | 432 | | |
433 | 433 | | |
434 | 434 | | |
| |||
653 | 653 | | |
654 | 654 | | |
655 | 655 | | |
656 | | - | |
657 | | - | |
658 | | - | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
659 | 665 | | |
660 | 666 | | |
661 | 667 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
| 111 | + | |
110 | 112 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
756 | 756 | | |
757 | 757 | | |
758 | 758 | | |
| 759 | + | |
759 | 760 | | |
760 | 761 | | |
761 | 762 | | |
| |||
0 commit comments