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

Mapping Enumeration values causes diverging implicit expansion error on Scala 2.10.0-M2, worked with 2.8 and 2.9

    Details

      Description

      I'm not sure if this is really a bug but atleast it seems like unintended consequence.

      Using MyEnumeration.values.map(p => (p -> DoSomehtingWith(p)) causes diverging implicit expansion error.
      This used to work on 2.8 and 2.9 and you can go around with MyEnumeration.values.toList.map but that seems strange and unnecessary.

      More verbose explanation here: http://stackoverflow.com/questions/9487425/enumeration-and-mapping-with-scala-2-10

        Activity

        Hide
        Hubert Plociniczak added a comment -

        Adriaan: Why is this not critical, since it is a regression?

        Show
        Hubert Plociniczak added a comment - Adriaan: Why is this not critical, since it is a regression?
        Hide
        Adriaan Moors added a comment - - edited

        This is a library issue, probably caused by https://github.com/scala/scala/commit/2d0f82898d
        newCanBuildFrom for SortedSet is competing with the normal canBuildFrom.

        Since there's an easy workaround (add a toList) and unlikely to be the compiler's fault, lowering priority and re-assigning.

        object Phrase extends Enumeration {
          type Phrase = Value
          val PHRASE1 = Value("My phrase 1")
          val PHRASE2 = Value("My phrase 2")
        }
        
        class Entity(text:String)
        
        object Test {
            val myMapWithPhrases = Phrase.values/*.toList*/.map(p => (p -> new Entity(p.toString))).toMap
        }
        
        Show
        Adriaan Moors added a comment - - edited This is a library issue, probably caused by https://github.com/scala/scala/commit/2d0f82898d newCanBuildFrom for SortedSet is competing with the normal canBuildFrom. Since there's an easy workaround (add a toList) and unlikely to be the compiler's fault, lowering priority and re-assigning. object Phrase extends Enumeration { type Phrase = Value val PHRASE1 = Value("My phrase 1") val PHRASE2 = Value("My phrase 2") } class Entity(text:String) object Test { val myMapWithPhrases = Phrase.values/*.toList*/.map(p => (p -> new Entity(p.toString))).toMap }
        Hide
        Adriaan Moors added a comment -

        the other workaround would be to provide an instance of Ordering at Entity:

        implicit object ord extends Ordering[Entity] { def compare(x: Entity, y: Entity) = ??? }
        

        since values is a SortedSet, that's needed for its canBuildFrom

        Stefan, I think we can close, but I'll let you have a second look since you know in more detail what's going on.

        Show
        Adriaan Moors added a comment - the other workaround would be to provide an instance of Ordering at Entity: implicit object ord extends Ordering[Entity] { def compare(x: Entity, y: Entity) = ??? } since values is a SortedSet, that's needed for its canBuildFrom Stefan, I think we can close, but I'll let you have a second look since you know in more detail what's going on.
        Hide
        Stefan Zeiger added a comment -

        I wish I knew what's going on. This canBuildFrom stuff is a hack (overriding newCanBuildFrom in SortedSet) upon a hack (needing both canBuildFrom and newCanBuildFrom in the first place) and I don't fully understand the latter.

        The reason for needing the SortedSet hack is that the standard canBuildFrom for SortedSets only works for sets with a user-specified ordering (even though SortedSet itself has no such requirement).

        I think it's a legitimate bug that should be fixed but off the top of my head I can't think of a good solution that won't further complicate the implementation (with the risk of creating new bugs in slightly different situations).

        Show
        Stefan Zeiger added a comment - I wish I knew what's going on. This canBuildFrom stuff is a hack (overriding newCanBuildFrom in SortedSet) upon a hack (needing both canBuildFrom and newCanBuildFrom in the first place) and I don't fully understand the latter. The reason for needing the SortedSet hack is that the standard canBuildFrom for SortedSets only works for sets with a user-specified ordering (even though SortedSet itself has no such requirement). I think it's a legitimate bug that should be fixed but off the top of my head I can't think of a good solution that won't further complicate the implementation (with the risk of creating new bugs in slightly different situations).
        Hide
        Jason Zaugg added a comment -

        Sounds like this needs a library change; we'll have to defer to 2.11 due to the forward binary compatibility regime.

        Show
        Jason Zaugg added a comment - Sounds like this needs a library change; we'll have to defer to 2.11 due to the forward binary compatibility regime.
        Hide
        Grzegorz Kossakowski added a comment -

        Unassigning and rescheduling to M7 as previous deadline was missed.

        Show
        Grzegorz Kossakowski added a comment - Unassigning and rescheduling to M7 as previous deadline was missed.

          People

          • Assignee:
            Unassigned
            Reporter:
            Janne Sinivirta
          • Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

            • Created:
              Updated:

              Development