From e53ace1a2dc8d58d99508a5f058b599761a23fa2 Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Thu, 2 Feb 2017 16:43:21 +0100 Subject: Weaken assumption in mergeCompanionDefs Previously `mergeCompanionDefs` 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 true. 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$`. --- compiler/src/dotty/tools/dotc/typer/Namer.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'compiler/src/dotty/tools/dotc/typer/Namer.scala') diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 1672512a7..772d9385b 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -491,7 +491,8 @@ class Namer { typer: Typer => if (cdef.isClassDef) { classDef(name) = cdef cdef.attachmentOrElse(ExpandedTree, cdef) match { - case Thicket(cls :: mval :: (mcls @ TypeDef(_, _: Template)) :: crest) => + case Thicket(cls :: mval :: (mcls @ TypeDef(mname, _: Template)) :: crest) + if name.moduleClassName == mname => moduleDef(name) = mcls case _ => } @@ -505,7 +506,8 @@ class Namer { typer: Typer => classDef get name.toTypeName match { case Some(cdef) => cdef.attachmentOrElse(ExpandedTree, cdef) match { - case Thicket(cls :: mval :: TypeDef(_, compimpl: Template) :: crest) => + case Thicket(cls :: mval :: TypeDef(mname, compimpl: Template) :: crest) + if name.moduleClassName == mname => val mcls1 = cpy.TypeDef(mcls)( rhs = cpy.Template(impl)(body = compimpl.body ++ impl.body)) mdef.putAttachment(ExpandedTree, Thicket(vdef :: mcls1 :: rest)) -- cgit v1.2.3