Open
Description
reproduction steps
using Scala 2.12.13,
The following code seems to never compile, presumably the compiler gets into some kind of trouble while inferring the type of the map being constructed:
case class DocumentId(tpe: String, value: String)
sealed trait KeyType extends Product with Serializable
case class StringKey(k: String) extends KeyType
case class DateKey(k: String) extends KeyType
object Example {
// ---- No explicit type provided ----
val expected = Map(
DocumentId("doc1", "1") -> Set(
Map(
StringKey("businessname") -> "eagle invest",
DateKey("start_date") -> java.sql.Date.valueOf("2017-01-01")
)
),
DocumentId("doc2", "1") -> Set(
Map(StringKey("address") -> "London, UK"),
Map(StringKey("address") -> "London")
)
)
}
// compiler falls over trying to infer Map[DocumentId, Set[Map[Any, Any]]]
When I add an explicit type, the code compiles fine:
case class DocumentId(tpe: String, value: String)
sealed trait KeyType extends Product with Serializable
case class StringKey(k: String) extends KeyType
case class DateKey(k: String) extends KeyType
object Example {
// ---- Explicit type provided ----
val expected: Map[DocumentId, Set[Map[Any, Any]]] = Map(
DocumentId("doc1", "1") -> Set(
Map(
StringKey("businessname") -> "eagle invest",
DateKey("start_date") -> java.sql.Date.valueOf("2017-01-01")
)
),
DocumentId("doc2", "1") -> Set(
Map(StringKey("address") -> "London, UK"),
Map(StringKey("address") -> "London")
)
)
}
The same code compiles fine without any explicit type in both 2.11 and 2.13 interestingly.
Examples on Scastie:
- Without explicit type: https://scastie.scala-lang.org/ZvGH9eW6QAKyjZpenqr2AA
- With explicit type: https://scastie.scala-lang.org/Q49YYU8ZTmOmaPV9Ao4A6g
- 2.11 without explicit type: https://scastie.scala-lang.org/8fu5mPimQziUXUwkpExO3w
- 2.13 without explicit type: https://scastie.scala-lang.org/dHQQpGuLR2OmnP1BuCj9Eg
problem
compiler gets stuck and eventually dies