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.

warn "dead code following this construct" when using * or any

See original GitHub issue

I’m not sure if thats due to my config but whenever I try to use any or * without specyfing type parameters I get

[error] Foo.scala: dead code following this construct
[error]       foo.bar(*).shouldReturn(List())
[error]               ^

This happens because compiler infers it to Nothing. I’m not sure if it can be fixed though…

Workaround for now is to add the following to build.sbt

scalacOptions in Test -= "-Ywarn-dead-code",

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
bbonannocommented, May 20, 2019

@LeonardMeyer if you specify the type to the Any matcher (or add -Ywarn-dead-code just for the test code) that problem goes away. Scalac doesn’t have type inference on parameters, so I’m afraid there is no way to solve this. My preferred choice is to disable that warning for test code as I prefer the clean API without the types for the any matchers, but if you don’t mind that you can add said types and problem solved.

0reactions
dormelamedcommented, Apr 6, 2022

For me, It wasn’t enough to add the Test / scalacOptions -= "-Ywarn-dead-code" at the build.sbt file. If you have the same problem and you are using IntelliJ. Go to sbt -> auto-reload settings -> compiler -> scala compiler -> additional compiler options. And delete the “-Ywarn-dead-code” from there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

scala - Why do I get 'Dead code following this construct' with ...
Nothing is actually a valid, required return type for any function that never returns, as well as being the type of a throw...
Read more >
Is this dead-code warning correct? If yes, how do I fix it?
This seems to be a bug in the compiler. Because get returns a value the warning doesn't make any sense (if asset is...
Read more >
mockito-scala
if you have enabled the compiler flag -Ywarn-dead-code , you will see the warning dead code following this construct when using the any...
Read more >
[Solved]-Why do I get 'Dead code following this construct' with ...
exit() ), etc. In your case, the fromJson call will cause a ClassCastException to be thrown when the JVM tries to cast its...
Read more >
MSC07-C. Detect and remove dead code
Code that is never executed is known as dead code. Typically, the presence of dead code indicates that a logic error has occurred...
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