Skip to content

Commit f3a0b01

Browse files
committed
Weaken assumption in mergeCompanionDefs
Previously it assumes that if the attachment of class `Foo` is as follows: x :: y :: tdef @ TypeDef(_, templ) Then the `tdef` must be `Foo$`. When there are multiple pre-typer transforms, this is not necessarily tree. For example, an annotation macro expansion may expand a non-case class `Foo` to `class Foo; object FooA`. We need to check the name of `tdef` to be equal to `Foo$`.
1 parent 3e65cff commit f3a0b01

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ class Namer { typer: Typer =>
491491
if (cdef.isClassDef) {
492492
classDef(name) = cdef
493493
cdef.attachmentOrElse(ExpandedTree, cdef) match {
494-
case Thicket(cls :: mval :: (mcls @ TypeDef(_, _: Template)) :: crest) =>
494+
case Thicket(cls :: mval :: (mcls @ TypeDef(mname, _: Template)) :: crest)
495+
if name ++ nme.MODULE_SUFFIX == mname =>
495496
moduleDef(name) = mcls
496497
case _ =>
497498
}
@@ -505,7 +506,8 @@ class Namer { typer: Typer =>
505506
classDef get name.toTypeName match {
506507
case Some(cdef) =>
507508
cdef.attachmentOrElse(ExpandedTree, cdef) match {
508-
case Thicket(cls :: mval :: TypeDef(_, compimpl: Template) :: crest) =>
509+
case Thicket(cls :: mval :: TypeDef(mname, compimpl: Template) :: crest)
510+
if name ++ nme.MODULE_SUFFIX == mname =>
509511
val mcls1 = cpy.TypeDef(mcls)(
510512
rhs = cpy.Template(impl)(body = compimpl.body ++ impl.body))
511513
mdef.putAttachment(ExpandedTree, Thicket(vdef :: mcls1 :: rest))

0 commit comments

Comments
 (0)