Closed
Description
Compiler version
3.0.0-RC3
Minimized code
sealed trait Base { def str: String }
case class One(str: String) extends Base
case class Two(str: String) extends Base
case class Three(str: String) extends Base
case class Item(_id: String)
private def doWithItem[T <: (One | Two | Three)](item: Item, value: T, action: (T) => Item) = doWithItemId(item._id, value, action)
private def doWithItemId[T <: (One | Two | Three)](itemId: String, value: T, action: (T) => Item) = { println(value.str); Item("_id") }
Output
Compile error:
Found: (action : T => Item)
Required: T² => Item
where: T is a type in method doWithItem with bounds <: One | Two | Three
T² is a type variable with constraint >: (value : T) and <: One | Two | Three
Expectation
The expectation is not having a compile error. If you reduce the ADT to just One
and Two
and constrain T
on (One | Two)
, it works.
Scastie: https://scastie.scala-lang.org/SAjrgcaoRS2fn7iyDhJnzg