Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Scala 2.11.1-RC1
    • Component/s: Misc Compiler
    • Labels:
      None

      Description

      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) }
                                ^
      

        Issue Links

          Activity

          Hide
          Lukas Rytz added a comment -

          i tried fixing it but failed on the second point:

          http://github.com/soundrabbit/scala/commit/9cfe04f6f765fbfd7fad4547e910dc05e4e47cf2
          
          Show
          Lukas Rytz added a comment - i tried fixing it but failed on the second point: http://github.com/soundrabbit/scala/commit/9cfe04f6f765fbfd7fad4547e910dc05e4e47cf2
          Hide
          Lukas Rytz added a comment -

          (In r22851) partial fix for see SI-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

          Show
          Lukas Rytz added a comment - (In r22851) partial fix for see SI-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
          Hide
          James Iry added a comment -

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

          Show
          James Iry added a comment - 2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.
          Show
          Eugene Burmako added a comment - https://github.com/scala/scala/pull/2816
          Hide
          Adriaan Moors added a comment -

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

          Show
          Adriaan Moors added a comment - Ping? Should we delay until 2.11.1-RC1 as it makes scalac produce fewer errors, not more?
          Hide
          Eugene Burmako added a comment -

          Pong. No objections from my side.

          Show
          Eugene Burmako added a comment - Pong. No objections from my side.

            People

            • Assignee:
              Eugene Burmako
              Reporter:
              Lukas Rytz
              TracCC:
              Erik Engbrecht, federico silva, Miles Sabin
            • Votes:
              1 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

              • Created:
                Updated:

                Development