Skip to content

Commit bf81fb6

Browse files
committed
Merge pull request #589 from smarter/fix/trait-init-name
TraitConstructors: Use a valid method name for the initializer (fix #577)
2 parents ca07c71 + 8f88589 commit bf81fb6

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ object SymDenotations {
315315
encl = encl.owner
316316
sep += "~"
317317
}
318-
if (owner.is(ModuleClass) && sep == "$") sep = "" // duplicate scalac's behavior: don't write a double '$$' for module class members.
318+
if (owner.is(ModuleClass, butNot = Package) && sep == "$") sep = "" // duplicate scalac's behavior: don't write a double '$$' for module class members.
319319
val fn = encl.fullNameSeparated(separator) ++ sep ++ name
320320
if (isType) fn.toTypeName else fn.toTermName
321321
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class TraitConstructors extends MiniPhaseTransform with SymTransformer {
2323

2424
def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation = {
2525
if (sym.isPrimaryConstructor && (sym.owner is Flags.Trait))
26-
sym.copySymDenotation(name = nme.INITIALIZER_PREFIX ++ sym.owner.fullName)
26+
// TODO: Someone needs to carefully check if name clashes are possible with this mangling scheme
27+
sym.copySymDenotation(name = nme.INITIALIZER_PREFIX ++ sym.owner.fullNameSeparated("$"))
2728
else sym
2829
}
2930

0 commit comments

Comments
 (0)