Skip to content
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

Wrong unreachable code reported for inline def pattern match #20395

Open
enif-lee opened this issue May 13, 2024 · 2 comments
Open

Wrong unreachable code reported for inline def pattern match #20395

enif-lee opened this issue May 13, 2024 · 2 comments
Labels
area:pattern-matching better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug

Comments

@enif-lee
Copy link

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

@enif-lee enif-lee added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 13, 2024
@enif-lee enif-lee changed the title Wron unreachable code report for inline def pattern match Wrong unreachable code reported for inline def pattern match May 13, 2024
@Gedochao Gedochao added area:pattern-matching better-errors Issues concerned with improving confusing/unhelpful diagnostic messages and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 13, 2024
@Gedochao
Copy link

BTW. E030 seems to be gone on Next (both 3.4.1 and 3.5.0-RC1-bin-20240512-99c4c00-NIGHTLY)
Although the problem remains, otherwise.

Output on 3.4.1:

-- [E121] Pattern Match Warning: /Users/pchabelski/IdeaProjects/scala-cli-tests/compiler-repro/repro.scala:8:9 
8 |    case _ => print("not match")
  |         ^
  |Unreachable case except for null (if this is intentional, consider writing case null => instead).
1 warning found

@mbovel
Copy link
Member

mbovel commented May 20, 2024

Is this issue similar to #20225?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:pattern-matching better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug
Projects
None yet
Development

No branches or pull requests

3 participants