Skip to content

Commit 0ebf36b

Browse files
committed
Mark concrete vals mixed in from Scala2 traits as mutable.
When a concrete val is mixed in from a Scala2 trait, a setter is generated, which is called by the `$init$` method. Since the assignment in this setter is not done in the constructor, it is nonsensical for the field to be immutable. This commit sets the Mutable flag on such fields. It only applies for vals coming from Scala2 traits. vals coming from Dotty traits are kept immutable.
1 parent b347d27 commit 0ebf36b

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/dotty/tools/dotc/transform/Memoize.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import Decorators._
9191
}
9292
} else if (sym.isSetter) {
9393
if (!sym.is(ParamAccessor)) { val Literal(Constant(())) = tree.rhs } // this is intended as an assertion
94+
field.setFlag(Mutable) // necessary for vals mixed in from Scala2 traits
9495
val initializer = Assign(ref(field), ref(tree.vparamss.head.head.symbol))
9596
cpy.DefDef(tree)(rhs = transformFollowingDeep(initializer)(ctx.withOwner(sym), info))
9697
}

0 commit comments

Comments
 (0)