diff options
author | liu fengyun <liu@fengy.me> | 2017-02-02 16:43:21 +0100 |
---|---|---|
committer | liu fengyun <liu@fengy.me> | 2017-02-02 16:55:35 +0100 |
commit | e53ace1a2dc8d58d99508a5f058b599761a23fa2 (patch) | |
tree | 0b59bb2c2002a67bd63268bfaf488b0f21a28d78 | |
parent | 3e65cff0caf4c671d3cf98da347792c85a4ac2de (diff) | |
download | dotty-e53ace1a2dc8d58d99508a5f058b599761a23fa2.tar.gz dotty-e53ace1a2dc8d58d99508a5f058b599761a23fa2.tar.bz2 dotty-e53ace1a2dc8d58d99508a5f058b599761a23fa2.zip |
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$`.
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/Namer.scala | 6 |
1 files changed, 4 insertions, 2 deletions
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)) |