Skip to content

Commit d91e42f

Browse files
committed
Fix setter name for Scala 2 traits
Solution: only use simple name for fields 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_=] However, the field created by the getter will be: scala[Qualified $ App][Qualified $$ initCode][Suffix $$local] It 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, due to the name mismatch. Consequently, the method `newField` will be called to create another field symbol without corresponding trees. After the change, the following field is generated instead: scala$App$$initCode[Suffix $$local] Now, the setter will be able to find the field via `sym.field`. This fix avoids generate a phantom symbol without corresponding trees.
1 parent cd6341e commit d91e42f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

compiler/src/dotty/tools/dotc/core/NameOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ object NameOps {
270270
original.fieldName
271271
}
272272
else getterName.fieldName
273-
else FieldName(name)
273+
else FieldName(name.toSimpleName)
274274

275275
def stripScala2LocalSuffix: TermName =
276276
if (name.isScala2LocalSuffix) name.asSimpleName.dropRight(1) else name

0 commit comments

Comments
 (0)