File tree 2 files changed +23
-0
lines changed
compiler/src/dotty/tools/dotc/transform
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,12 @@ class Memoize extends MiniPhase with IdentityDenotTransformer { thisPhase =>
150
150
// When transforming the getter, we determined that no field was needed.
151
151
// In that case we can keep the setter as is, with a () rhs.
152
152
tree
153
+ else if field.getter.is(ParamAccessor , butNot = Mutable ) then
154
+ // This is a trait setter (because not Mutable) for a param accessor.
155
+ // We must keep the () rhs of the trait setter, otherwise the value
156
+ // inherited from the trait will overwrite the value of the parameter.
157
+ // See tests/run/traitValOverriddenByParamAccessor.scala
158
+ tree
153
159
else
154
160
field.setFlag(Mutable ) // Necessary for vals mixed in from traits
155
161
val initializer =
Original file line number Diff line number Diff line change
1
+ trait Foo {
2
+ val someField : Int = 5
3
+ }
4
+
5
+ class SimpleFoo extends Foo
6
+
7
+ class Bar (override val someField : Int ) extends Foo
8
+
9
+ object Test {
10
+ def main (args : Array [String ]): Unit = {
11
+ val simpleFoo = new SimpleFoo
12
+ assert(simpleFoo.someField == 5 )
13
+
14
+ val bar = new Bar (44 )
15
+ assert(bar.someField == 44 )
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments