Skip to content

Commit f6d9fcb

Browse files
committed
Fix setter name for Scala 2 traits
Before the change, given the following code class A extends App The compiler will generate the following setter in the phase Mixin: scala[Qualified $ App][Qualified $_setter_$ scala$App$$initCode_=] After the change, the following setter is generated instead: scala[Qualified $ App][Qualified $$ initCode_=] The former will cause a problem in the phase Memoize in the line below: val field = sym.field.orElse(newField).asTerm The problem is that, for the setter, `sym.field` will be unable to find the field generated by the getter below, due to the name mismatch: scala[Qualified $ App][Qualified $$ initCode][Suffix $$local] Consequently, the method `newField` will be called to create another field symbol without corresponding trees. This fix avoids generate a phantom symbol without corresponding trees.
1 parent cd6341e commit f6d9fcb

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ class AugmentScala2Traits extends MiniPhase with IdentityDenotTransformer { this
4848

4949
private def augmentScala2Trait(mixin: ClassSymbol)(implicit ctx: Context): Unit = {
5050
def traitSetter(getter: TermSymbol) =
51+
val name = getter.ensureNotPrivate.name.asTermName.setterName
5152
getter.copy(
52-
name = getter.ensureNotPrivate.name
53-
.expandedName(getter.owner, TraitSetterName)
54-
.asTermName.setterName,
53+
name = name,
5554
flags = Method | Accessor,
5655
info = MethodType(getter.info.resultType :: Nil, defn.UnitType))
5756

0 commit comments

Comments
 (0)