Skip to content

pattern matching on class with F-bounded type parameter leads to "Type argument does not conform to upper bound" error #9781

@Sciss

Description

@Sciss

Minimized code

trait Txn[T <: Txn[T]]

trait Elem[T <: Txn[T]]

sealed trait State[+T]
final case class Done[T <: Txn[T]](elem: Elem[T]) extends State[T]
case object Busy extends State[Nothing]

trait Test[Out <: Txn[Out]] {
  def apply(opt: Option[State[Out]]): Any = opt match {
    case Some(state) =>
      state match {
        case Done(out)  => "foo"    // problem here
        case Busy       => throw new IllegalStateException("Cyclic object graph")
      }
      
    case None => "bar"
  }
}

Output

https://scastie.scala-lang.org/KKu1hRdCSMuZONlMT8afZw

error: Type argument T$1 does not conform to upper bound Txn[LazyRef(T$1)]

Expectation

Should work ( https://scastie.scala-lang.org/r1Z7nuR2SRKc6HssuxVLJQ )

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions