Skip to content

Weaken assumption in mergeCompanionDefs #1933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2017

Conversation

liufengyun
Copy link
Contributor

@liufengyun liufengyun commented Feb 2, 2017

Previously mergeCompanionDefs assumes that if the attachment of class Foo is as follows:

x :: y :: tdef @ TypeDef(_, templ)

Then 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$.

Review @odersky .

@liufengyun liufengyun requested a review from odersky February 2, 2017 15:46
@@ -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 ++ nme.MODULE_SUFFIX == mname =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NameOps has a moduleClassName method to do that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip @smarter 👍

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$`.
@odersky
Copy link
Contributor

odersky commented Feb 2, 2017

LGTM

@odersky odersky merged commit 368366a into scala:master Feb 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants