Skip to content

Concrete type refinement not seen in pattern matching #268

@S11001001

Description

@S11001001

This code compiles in Scala 2.11.4:

package typespatmat

sealed trait Box2[T]
final case class Int2(x: Int) extends Box2[Int]
final case class Str2(x: String)
                              extends Box2[String]

object Box2 {
  def double2[T](x: Box2[T]): T = x match {
    case Int2(i) => i * 2
    case Str2(s) => s + s
  }
}

In dotty 8336a0d, this gives:

[info] Running dotty.tools.dotc.Main ../sbt-project/src/main/scala/Box2.scala
[error] ../sbt-project/src/main/scala/Box2.scala:10: error: type mismatch:
[error]  found   : Int
[error]  required: T
[error]     case Int2(i) => i * 2
[error]                       ^
[error] ../sbt-project/src/main/scala/Box2.scala:11: error: type mismatch:
[error]  found   : String
[error]  required: T
[error]     case Str2(s) => s + s
[error]                       ^
[error] two errors found

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