Skip to content

Wrong unreachable code reported for inline def pattern match #20395

@enif-lee

Description

@enif-lee

Compiler version

3.3.3

Minimized code

sealed trait NodeId
case object Hi extends NodeId
case object Hello extends NodeId

extension(value: NodeId)
  inline def parse[T <: NodeId] = value match
    case t: T => print("match")
    case _ => print("not match")


@main
def main(): Unit = {
  Hi.parse[Hello.type]
}

Output

not match
[IJ]compile
[info] compiling 2 Scala sources to /Users/js_lee/git/personal/scala3-test/target/scala-3.3.3/classes ...
[warn] -- [E121] Pattern Match Warning: /Users/js_lee/git/personal/scala3-test/src/main/scala/main.scala:12:9 
[warn] 12 |    case _ => print("not match")
[warn]    |         ^
[warn]    |Unreachable case except for null (if this is intentional, consider writing case null => instead).
[warn] -- [E030] Match case Unreachable Warning: /Users/js_lee/git/personal/scala3-test/src/main/scala/main.scala:17:10 
[warn] 17 |  Hi.parse[Hello.type]
[warn]    |  ^^^^^^^^^^^^^^^^^^^^
[warn]    |  Unreachable case
[warn]    |----------------------------------------------------------------------------
[warn]    |Inline stack trace
[warn]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[warn]    |This location contains code that was inlined from main.scala:11
[warn] 11 |    case t: T => print("match")
[warn]    |         ^^^^
[warn]     ----------------------------------------------------------------------------
[warn] two warnings found

![image](https://github.com/scala/scala3/assets/9916002/dba8e346-3f3b-4a39-a1dd-c1472683407

Expectation

The case _ is reachable case but The compiler doesn't think so

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions