Skip to content

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

@scabug

Description

@scabug

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

scabug

scabug commented on Mar 2, 2012

@scabug
Author

Imported From: https://issues.scala-lang.org/browse/SI-5534?orig=1
Reporter: Janne Sinivirta (vertti)

scabug

scabug commented on Jul 17, 2012

@scabug
Author

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

scabug

scabug commented on Aug 7, 2012

@scabug
Author

@adriaanm said (edited on Aug 7, 2012 9:00:27 AM UTC):
This is a library issue, probably caused by scala/scala@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
}
scabug

scabug commented on Aug 7, 2012

@scabug
Author

@adriaanm said:
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.

scabug

scabug commented on Aug 7, 2012

@scabug
Author

@szeiger said:
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).

scabug

scabug commented on Jan 29, 2013

@scabug
Author

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

scabug

scabug commented on Oct 15, 2013

@scabug
Author

@gkossakowski said:
Unassigning and rescheduling to M7 as previous deadline was missed.

added this to the Backlog milestone on Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @scabug

        Issue actions

          Mapping Enumeration values causes diverging implicit expansion error on Scala 2.10.0-M2, worked with 2.8 and 2.9 · Issue #5534 · scala/bug