Scala Programming Language
  1. Scala Programming Language
  2. SI-3616

Enumeration.values is confused by methods returning Val instances

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.8.1
    • Component/s: Enumeration
    • Labels:
      None

      Description

      object X extends Enumeration {
          val Y = Value
      }
      object Fruit extends Enumeration {
          val x = X.Y
          val A,B,C = Value
      }
      
      
      scala> Fruit.values
      res0: Fruit.ValueSet = object$$Fruit.ValueSet(x, B, C)
      

        Issue Links

          Activity

          Hide
          Iulian Dragos added a comment -

          Paul, can you have a look?

          Show
          Iulian Dragos added a comment - Paul, can you have a look?
          Hide
          Mark Harrah added a comment -

          I could not reproduce this with trunk, although I could believe the issue is real from looking at the source for Enumeration. I tried with defining X and Fruit both inside and outside the REPL and also reordering `x`.

          Unless someone else can reproduce it, what version of Scala and Java and can you post a full example that runs outside the REPL?

          Show
          Mark Harrah added a comment - I could not reproduce this with trunk, although I could believe the issue is real from looking at the source for Enumeration. I tried with defining X and Fruit both inside and outside the REPL and also reordering `x`. Unless someone else can reproduce it, what version of Scala and Java and can you post a full example that runs outside the REPL?
          Hide
          Thomas Jung added a comment -

          The original version was 2.8.0.RC5 but I can reproduce it with 2.8.0.RC6.

          Welcome to Scala version 2.8.0.RC6 (Java HotSpot(TM) Client VM, Java 1.6.0_18).
          Type in expressions to have them evaluated.
          Type :help for more information.
          
          scala> object X extends Enumeration {
               |     val Y = Value
               | }
          defined module X
          
          scala> object Fruit extends Enumeration {
               |     val x = X.Y
               |     val A,B,C = Value
               | }
          defined module Fruit
          
          scala> Fruit.values
          res0: Fruit.ValueSet = object$$Fruit.ValueSet(x, B, C)
          
          Show
          Thomas Jung added a comment - The original version was 2.8.0.RC5 but I can reproduce it with 2.8.0.RC6. Welcome to Scala version 2.8.0.RC6 (Java HotSpot(TM) Client VM, Java 1.6.0_18). Type in expressions to have them evaluated. Type :help for more information. scala> object X extends Enumeration { | val Y = Value | } defined module X scala> object Fruit extends Enumeration { | val x = X.Y | val A,B,C = Value | } defined module Fruit scala> Fruit.values res0: Fruit.ValueSet = object$$Fruit.ValueSet(x, B, C)
          Hide
          Paul Phillips added a comment -

          (In r22446) Enumeration fixes. There was no way to do reflection-based naming
          correctly simply by inspecting method signatures (because a Value from
          a different Enumeration stored in a val looks identical to one from
          this Enumeration) so I have Value store the outer Enum for comparison
          purposes. This won't make anything new uncollectable because they
          already have an $$outer pointing there. This also simplified the
          reflection logic: it's an eq test rather than a series of heuristics.

          Closes SI-3616, SI-3615. Review by phaller.

          Show
          Paul Phillips added a comment - (In r22446) Enumeration fixes. There was no way to do reflection-based naming correctly simply by inspecting method signatures (because a Value from a different Enumeration stored in a val looks identical to one from this Enumeration) so I have Value store the outer Enum for comparison purposes. This won't make anything new uncollectable because they already have an $$outer pointing there. This also simplified the reflection logic: it's an eq test rather than a series of heuristics. Closes SI-3616 , SI-3615 . Review by phaller.
          Hide
          phmietti added a comment -

          The inspection seems to be broken still in 2.8.1.RC1. it works if I define the name for Value but breaks if the name is not defined.

          Welcome to Scala version 2.8.1.RC1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20).
          Type in expressions to have them evaluated.
          Type :help for more information.
          
          scala> object X extends Enumeration {
               | val a, b = Value 
               | }
          defined module X
          
          scala> object Y extends Enumeration {
               | val a = Value("a")
               | val b = Value("b")
               | }
          defined module Y
          
          scala> X.values
          res0: X.ValueSet = X.ValueSet(a, b)
          
          scala> X.values
          res1: X.ValueSet = X.ValueSet(a, b, Value)
          
          scala> Y.values
          res2: Y.ValueSet = Y.ValueSet(a, b)
          
          scala> Y.values
          res3: Y.ValueSet = Y.ValueSet(a, b)
          
          Show
          phmietti added a comment - The inspection seems to be broken still in 2.8.1.RC1. it works if I define the name for Value but breaks if the name is not defined. Welcome to Scala version 2.8.1.RC1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20). Type in expressions to have them evaluated. Type :help for more information. scala> object X extends Enumeration { | val a, b = Value | } defined module X scala> object Y extends Enumeration { | val a = Value("a") | val b = Value("b") | } defined module Y scala> X.values res0: X.ValueSet = X.ValueSet(a, b) scala> X.values res1: X.ValueSet = X.ValueSet(a, b, Value) scala> Y.values res2: Y.ValueSet = Y.ValueSet(a, b) scala> Y.values res3: Y.ValueSet = Y.ValueSet(a, b)
          Hide
          Hubert Plociniczak added a comment -

          That one seems to be a duplicate of SI-3687 (see comments of that ticket). It might be actually that this is the other way around, but it would be nice to keep things in one place. Assigning to myself as I was appointed to fix enumeration bugs.

          Show
          Hubert Plociniczak added a comment - That one seems to be a duplicate of SI-3687 (see comments of that ticket). It might be actually that this is the other way around, but it would be nice to keep things in one place. Assigning to myself as I was appointed to fix enumeration bugs.
          Hide
          Hubert Plociniczak added a comment -

          (In r23893) Closes SI-3687, SI-3719, SI-3950, SI-3616. Plus removed some deprecated stuff for 2.9. Review by extempore

          Show
          Hubert Plociniczak added a comment - (In r23893) Closes SI-3687 , SI-3719 , SI-3950 , SI-3616 . Plus removed some deprecated stuff for 2.9. Review by extempore

            People

            • Assignee:
              Hubert Plociniczak
              Reporter:
              Thomas Jung
              TracCC:
              hanna, Mark Harrah
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development