Spurious unreachable case warning
See original GitHub issueCompiler 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:
- Created a year ago
- Comments:10 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think in my case it’s a valid warning 😄
Created a small repro — https://github.com/lampepfl/dotty/issues/16379