Skip to content

Create dummy companions for classes without a real one #2149

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
Apr 4, 2017

Conversation

smarter
Copy link
Member

@smarter smarter commented Mar 29, 2017

In #2139 I added code to create dummy companions for companion-less
objects, but not for companion-less classes because I thought it wasn't
needed. But it turns out that even if the classpath only has Foo.class
and not Foo$.class, a module for Foo is entered by
initializeFromClassPath when it calls enterClassAndModule, so we
have to add dummy companions to classes. I don't have a test to
illustrate this issue, but note that it fixes the incremental
compilation bug demonstrated by
https://github.com/dotty-staging/dotty/commits/incremental-compilation-bug.

Note: I verified that adding a dummy companion to "class Foo" did not
cause the backend to emit a Foo$.class, so this should have no visible
impact.

In scala#2139 I added code to create dummy companions for companion-less
objects, but not for companion-less classes because I thought it wasn't
needed. But it turns out that even if the classpath only has `Foo.class`
and not `Foo$.class`, a module for `Foo` is entered by
`initializeFromClassPath` when it calls `enterClassAndModule`, so we
have to add dummy companions to classes. I don't have a test to
illustrate this issue, but note that it fixes the incremental
compilation bug demonstrated by
https://github.com/dotty-staging/dotty/commits/incremental-compilation-bug.

Note: I verified that adding a dummy companion to "class Foo" did not
cause the backend to emit a Foo$.class, so this should have no visible
impact.
@smarter smarter requested review from odersky and DarkDimius March 29, 2017 16:32
@sjrd
Copy link
Member

sjrd commented Mar 29, 2017

This could be an issue for code like this:

object Foo {
  class Bar
  val Bar = "babar"
}

@smarter
Copy link
Member Author

smarter commented Mar 29, 2017

@sjrd The dummy companions are only added for top-level classes and objects so it should be fine. Even if it wasn't the case, no dummy companion for class Bar would be added if a term named Bar was declared in the same scope.

@smarter
Copy link
Member Author

smarter commented Apr 3, 2017

Ping for review.

@DarkDimius
Copy link
Contributor

LGTM

@DarkDimius DarkDimius merged commit abd09ff into scala:master Apr 4, 2017
@allanrenucci allanrenucci deleted the fix/false-companion-2 branch December 14, 2017 19:22
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.

3 participants