Skip to content

Unreachable code warning for reachable match case #3543

Closed
@nicolasstucki

Description

@nicolasstucki
import scala.util.matching.Regex

object Test {
  def main(args: Array[String]): Unit = {
    foo("c" :: Nil, false)
  }

  def foo(remaining: List[String], inCodeBlock: Boolean): Unit = {
    remaining match {
      case CodeBlockEndRegex(before) :: ls =>
      case SymbolTagRegex(name) :: ls if !inCodeBlock => println("OK")
      case _ =>
    }
  }

  val CodeBlockEndRegex = new Regex("(b)")
  val SymbolTagRegex = new Regex("(c)")
}

Emits the folowing warining but should not.

11 |      case SymbolTagRegex(name) :: ls if !inCodeBlock => println("OK")
   |                                                      ^^^^^^^^^^^^^^^^
   |                                                      unreachable code

The code is correctly compiled and executed.

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