question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spurious unreachable case warning

See original GitHub issue

Compiler version

3.2.0

Minimized code

sealed trait Nat
case class Zero() extends Nat
case class Succ[N <: Nat](n: N) extends Nat

def foo(n: Nat): Int = n match
  case Zero() => 0
  case Succ(Zero()) => 1
  case _ => 2 // warning for this line

foo(Succ(Succ(Zero()))) // evaluates to 2

Compiler warning

Unreachable case except for null (if this is intentional, consider writing case null => instead).

Expectation

No warning

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tusharmathcommented, Nov 17, 2022

I think in my case it’s a valid warning 😄

1reaction
tusharmathcommented, Nov 19, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Spurious "unreachable case branch" with multi-way ... - GitHub
I see an "unreachable case branch" warning. Expected behavior. No warnings.
Read more >
Wswitch-unreachable warning with -ftrivial-auto-var-init=zero
Now, for this particular case, it surely could be handled like: auto tmp_ = bar (x, y); { int y; switch (tmp_) {...
Read more >
Spurious error "switch label is unreachable" : IDEA-237669
, IntelliJ spuriously marks the case labels as "not reachable". TypeKind is an ordinary enum, and value may be an Integer . If...
Read more >
C++/CLI: false positive C4702 unreachable code warning ...
Adding it here in case someone searches for warning C4702 in combination with std::abort or std::terminate . ref class B sealed { public:...
Read more >
c++ - Boost.Beast C4702 "unreachable" compiler warning on ...
Building with Boost-1.67.0 and VS on Windows, I get a C4702 "unreachable" warning for boost::beast::http::detail::verb_to_string(verb v) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found