Skip to content

Problem with ensuring every class has a companion object #314

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

Closed
odersky opened this issue Dec 19, 2014 · 1 comment
Closed

Problem with ensuring every class has a companion object #314

odersky opened this issue Dec 19, 2014 · 1 comment

Comments

@odersky
Copy link
Contributor

odersky commented Dec 19, 2014

Have a look at pending/pos/S5.scala. Here we have an inner class with the same name "n" as
a val in the same scope. It follows that creating a companion object for the class will create an illegal
double definition. This currently leads to an override error in RefChecks because the newly created
companion object does not have the same type as the val overridden by the same-named value in
the class.

What should we do about this? This looks very messy. I see three alternatives, all not super attractive:

  1. We do not generate companion classes automatically. But then where to put extension methods, tailrec methods, etc?
  2. We disallow classes to have the same name (module type/term) as a value in the same scope. That looks irregular and hacky.
  3. We somehow name companions differently if they conflict. That seems to be the best solution,
    but it looks complicated.

Any other ideas?

@odersky
Copy link
Contributor Author

odersky commented Dec 19, 2014

In fact, (3) turned out to be quite feasible. We now avoid name clashes when generating companion object. See cf6b62f in #313.

@odersky odersky closed this as completed Dec 19, 2014
tgodzik added a commit to tgodzik/scala3 that referenced this issue Apr 29, 2025
Backport "No warning for parameter of overriding method" to 3.3 LTS
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

No branches or pull requests

1 participant