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

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

Open
scabug opened this issue Mar 2, 2012 · 7 comments

Comments

Projects
None yet
1 participant
@scabug
Copy link

commented Mar 2, 2012

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

@scabug

This comment has been minimized.

Copy link
Author

commented Mar 2, 2012

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

@scabug

This comment has been minimized.

Copy link
Author

commented Jul 17, 2012

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

@scabug

This comment has been minimized.

Copy link
Author

commented Aug 7, 2012

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

This comment has been minimized.

Copy link
Author

commented Aug 7, 2012

@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

This comment has been minimized.

Copy link
Author

commented Aug 7, 2012

@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

This comment has been minimized.

Copy link
Author

commented Jan 29, 2013

@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

This comment has been minimized.

Copy link
Author

commented Oct 15, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.