8

In scala when compiling with -Ywarn-unused, implicit parameters are marked as never used even if they are used in implicit scope.

For example

class MyClass(implicit: ec: ExecutionContext) { def fun = Future.successful("hi").map(_.length) } 

This is problematic when running with -Xfatal-warnings as well.

Is there a way to hint to the compiler that these parameters are in fact used? If not, is there another way to ensure code won't compile with unused parameters and declarations?

2
  • 2
    Not every method from Future need ExecutionContext. Try replacing successful with Future.apply. Commented May 29, 2019 at 5:24
  • @LuisMiguelMejíaSuárez perfect, that's exactly what I was looking for. Go ahead and submit that as an answer! Commented May 29, 2019 at 18:55

1 Answer 1

14

Use the -Ywarn-macros:after flag too. It basically tells the compiler to make the unused checks after macro expansion, that usually solve the problem of unused implicits.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.