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.

Unreachable case warning could point to previous matching case

See original GitHub issue

Given:

trait Foo
class One extends Foo
class Two extends Foo
class Bla extends One

object Test {
  def test(f: Foo) = f match {
    case f: One =>
    case f: Two =>
    case f: Bla =>
  }
}

We get the warning:

-- [E120] Only null matched Warning: try/caseun.scala:10:9 ---------------------
10 |    case f: Bla =>
   |         ^^^^^^
   |         Only null is matched. Consider using `case null =>` instead.

This is confusing since it doesn’t explain why only null is matched. Here it’s easy to see that this is because we matched on One previously and that Bla is a subtype of One, but in a long series of case this might be very hard to understand. A better warning message would explain all of this.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Blaisorbladecommented, Aug 16, 2018

Created #4953 for -Ylog, and closing with stat:revisit.

1reaction
abelncommented, Aug 16, 2018

I see. That feels like a change with larger implications, though. I’d agree with Fengyun that we either put on hold or close this, since we now have the correct error message that makes more sense. We could file a separate bug for “-Ylog”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unreachable code in Scala Pattern Matching - Stack Overflow
The pattern matching is sequential for match which means it will first match price with 1st case which is price: Int then Float...
Read more >
Scala 'unreachable code due to variable pattern' warning ...
I hope this explanation about the "unreachable code due to variable pattern" warning/error message has been helpful. scala · case · compiler.
Read more >
Missing unreachable match warning with only two cases #12559
there should be an unreachable warning for case e: LogEventWithMarker , as which happens when we add another child to LogEvent (uncomment ...
Read more >
warning CS1062: Unreachable code detected. is this normal ...
Cases in a switch statement do not need to end in break , they just need to have an unreachable end (that the...
Read more >
46476 – Missing Warning about unreachable code after return
Running the same static analyser over the source code of a recent gcc found 22 occurrences of this kind of problem. Here they...
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