Skip to content

Inline matches don't refine on the RHS #5564

Open
@milessabin

Description

@milessabin

Equalities between types established by the cases of inline matches aren't known on the RHS,

object Test {
  import scala.compiletime._
  inline def foo[T](t: T): T =
    inline erasedValue[T] match {
      case _: Int => 23
      case _ => t
    }
}
-- [E007] Type Mismatch Error: tests/run/typeclass-derivation3.scala:5:21 ----
  5 |      case _: Int => 23
    |                     ^^
    |                     found:    Int(23)
    |                     required: T
one error found

Adding a cast allows this to compile,

object Test {
  import scala.compiletime._
  inline def foo[T](t: T): T =
    inline erasedValue[T] match {
      case _: Int => 23.asInstanceOf[T]
      case _ => t
    }
}

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