Skip to content
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

companions and method-owned case classes #3772

Closed
scabug opened this issue Aug 17, 2010 · 10 comments
Closed

companions and method-owned case classes #3772

scabug opened this issue Aug 17, 2010 · 10 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Aug 17, 2010

scala> def f { object C; case class C(); }
<console>:5: error: C is already defined as object C
       def f { object C; case class C(); }
                                    ^

scala> def g { case class C(); object C; }
<console>:5: error: C is already defined as (compiler-generated) case class companion object C
       def g { case class C(); object C; }
                                      ^

What happens: ensureCompanionObject looks up a term symbol m in the current scope named after the class. Then there are two cases:

  • If the companion object is given before the class then it's symbol m is actually found. But then, inCurrentScope(m) is called which returns false. I don't understand what this method actually checks. But this should be easy to fix.
  • If the companion object is given after the class we have a bigger problem. The symbol of the given module is not found (m == NoSymbol) because the corresponding enterModuleSymbol has not run yet, it will only run later in the namer phase.

Another way to reproduce the same problem:

scala> def h { case class C(x: Int = 1) }
<console>:5: error: C is already defined as (compiler-generated) case class companion object C
       def h { case class C(x: Int = 1) }
                          ^
@scabug
Copy link
Author

scabug commented Aug 17, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3772?orig=1
Reporter: @lrytz
Affected Versions: 2.10.6, 2.11.8, 2.12.0

@scabug
Copy link
Author

scabug commented Aug 17, 2010

@lrytz said:
i tried fixing it but failed on the second point:

http://github.com/soundrabbit/scala/commit/9cfe04f6f765fbfd7fad4547e910dc05e4e47cf2

@scabug
Copy link
Author

scabug commented Aug 27, 2010

@lrytz said:
(In r22851) partial fix for see #3772. remaining problem is when the explicit companion object is specified after the class:

  scala> def g { case class C(); object C; }
  <console>:5: error: C is already defined as (compiler-generated) case class companion object C
         def g { case class C(); object C; }
                                        ^

review by odersky

@scabug
Copy link
Author

scabug commented May 20, 2013

@JamesIry said:
2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.

@scabug
Copy link
Author

scabug commented Aug 10, 2013

@xeno-by said:
scala/scala#2816

@scabug
Copy link
Author

scabug commented Feb 10, 2014

@adriaanm said:
Ping? Should we delay until 2.11.1-RC1 as it makes scalac produce fewer errors, not more?

@scabug
Copy link
Author

scabug commented Feb 10, 2014

@xeno-by said:
Pong. No objections from my side.

@scabug
Copy link
Author

scabug commented Apr 12, 2016

Eyal Roth (errr) said:
I suspect it also affects #9748, which can't be worked around afaik.

@scabug
Copy link
Author

scabug commented Nov 17, 2016

@retronym said:
Looks like we also had a bug in companionSymbolOf. I think this addresses all the issues; I'll schedule this for 2.12.2.

scala/scala@2.11.x...retronym:ticket/3772

@scabug
Copy link
Author

scabug commented Nov 21, 2016

@retronym said:
scala/scala#5550

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants