Skip to content

Commit 50e3d4a

Browse files
committed
Allow value expansion of modules in mergeCompanionDefs
1 parent fc39792 commit 50e3d4a

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -499,23 +499,28 @@ class Namer { typer: Typer =>
499499
}
500500
for (mdef @ ModuleDef(name, _) <- stats if !mdef.mods.is(Flags.Package)) {
501501
val typName = name.toTypeName
502-
// Expansion of object is a flattened thicket with the first two elements being:
503-
// module val :: module class :: rest
504-
val Thicket(vdef :: (mcls @ TypeDef(_, impl: Template)) :: rest) = expanded(mdef)
505-
moduleDef(typName) = mcls
506-
classDef get name.toTypeName match {
507-
case Some(cdef) =>
508-
cdef.attachmentOrElse(ExpandedTree, cdef) match {
509-
case Thicket(cls :: mval :: TypeDef(mname, compimpl: Template) :: crest)
510-
if name.moduleClassName == mname =>
511-
val mcls1 = cpy.TypeDef(mcls)(
512-
rhs = cpy.Template(impl)(body = compimpl.body ++ impl.body))
513-
mdef.putAttachment(ExpandedTree, Thicket(vdef :: mcls1 :: rest))
514-
moduleDef(typName) = mcls1
515-
cdef.putAttachment(ExpandedTree, Thicket(cls :: crest))
516-
case _ =>
502+
expanded(mdef) match {
503+
// Expansion of non-enum object is a flattened thicket with the first two elements being:
504+
// module val :: module class :: rest
505+
case Thicket(vdef :: (mcls @ TypeDef(_, impl: Template)) :: rest) =>
506+
moduleDef(typName) = mcls
507+
classDef get name.toTypeName match {
508+
case Some(cdef) =>
509+
cdef.attachmentOrElse(ExpandedTree, cdef) match {
510+
case Thicket(cls :: mval :: TypeDef(mname, compimpl: Template) :: crest)
511+
if name.moduleClassName == mname =>
512+
val mcls1 = cpy.TypeDef(mcls)(
513+
rhs = cpy.Template(impl)(body = compimpl.body ++ impl.body))
514+
mdef.putAttachment(ExpandedTree, Thicket(vdef :: mcls1 :: rest))
515+
moduleDef(typName) = mcls1
516+
cdef.putAttachment(ExpandedTree, Thicket(cls :: crest))
517+
case _ =>
518+
}
519+
case none =>
517520
}
518-
case none =>
521+
case _ =>
522+
// An enum module is expanded to a val. This val is not merged
523+
// with a companion module.
519524
}
520525
}
521526
}

0 commit comments

Comments
 (0)