Skip to content

Unreachable code error when matching on Scala 3 sealed trait #13106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jadenPete opened this issue Jun 6, 2025 · 3 comments
Closed

Unreachable code error when matching on Scala 3 sealed trait #13106

jadenPete opened this issue Jun 6, 2025 · 3 comments
Milestone

Comments

@jadenPete
Copy link

Reproduction steps

Scala 2 version: 2.13.16
Scala 3 version: 3.6.3

  1. Compile the following code with Scala 3:
sealed trait Pet

case class Dog(name: String) extends Pet
case class Cat(name: String) extends Pet
  1. Compile the following code with Scala 2:
class PetPrinter {
  def printPet(pet: Pet): Unit = println(
    pet match {
      case Dog(_) => "I'm a dog."
      case Cat(_) => "I'm a cat."
    },
  )
}
  1. Observe the following compiler error:
[Error] .../Scala2.scala:5:22: unreachable code
[Error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=other-match-analysis, site=PetPrinter.printPet
[Error]       case Cat(_) => "I'm a cat."
[Error] 

Problem

The Scala 2 code should've compiled successfully.

@lrytz lrytz added this to the Backlog milestone Jun 12, 2025
@lrytz
Copy link
Member

lrytz commented Jun 12, 2025

I tried but could not reproduce this; I'm not getting the "unreachable code" warning. Can you share step by step instructions, or a small project that shows the issue?

@lrytz
Copy link
Member

lrytz commented Jun 16, 2025

Please reopen if appropriate.

@lrytz lrytz closed this as completed Jun 16, 2025
@som-snytt
Copy link

Me neither, using scala-cli.

//> using scala 2.13.16
//> using options -Ytasty-reader -Xsource:3-cross -Xlint
//> using dep org.scala-lang:scala3-library_3:3.7.1

other-match-analysis is Scala 2; does [Error] mean sbt?

@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants