warn "dead code following this construct" when using * or any
See original GitHub issueI’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:
- Created 5 years ago
- Reactions:3
- Comments:11 (8 by maintainers)
Top 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 >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
@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.
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.