Skip to content

Pattern Matching Bug When matching against case classes defined in trait #9672

Open
@scabug

Description

@scabug

When pattern matching, compiler :

  • doesn't emit the "match is not exhaustive" warning (it should)
  • emits "unreachable code" (it should not)
trait Hierarchy {
  sealed trait Expr
}
trait If {
  this: Hierarchy =>
  case class If(cond: Expr, yes: Expr, no: Expr) extends Expr
}
trait Word {
  this: Hierarchy =>
  case class Word(name: String) extends Expr
}
trait IntExpr {
  this: Hierarchy =>
  case class IntExpr(value : Int) extends Expr
}

object SimpleExpr extends Hierarchy with If with Word with IntExpr
//object OtherExpr extends Hierarchy with If with IntExpr

object Demo extends App {
  import SimpleExpr._
  def func(expr: Expr) = expr match {
    case If(cond, yes, no) => cond
    case Word(name) => name
    // compiler should emit warning "missing case statement"
    // emits the wrong warning "unreachable code"
  }
}

see also here : http://stackoverflow.com/questions/35259337/scala-compiler-emits-no-warning-when-pattern-matching-against-a-sealed-trait

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)mixinpatmat

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions