DEV Community

Parambir Singh
Parambir Singh

Posted on

2 1

scalac -feature

A useful option to turn on for the scala compiler is -feature. It emits warning and location for usages of features that should be imported explicitly.

An example such an advanced feature is implicit conversions. An implicit conversion is an implicit value of type A => B. e.g.

def main(args: Array[String]): Unit = {
    val s = "Hello, world!"
    val len: Int = s
    println(len)
}

implicit def stringToInt(s: String): Int = s.length
Enter fullscreen mode Exit fullscreen mode

Compiling this piece of code with the -feature scalac flag enabled gives the following warning:

[warn] Main.scala:8:16: implicit conversion method stringToInt should be enabled
[warn] by making the implicit value scala.language.implicitConversions visible.
[warn] ----
[warn] This can be achieved by adding the import clause 'import scala.language.implicitConversions'
[warn] or by setting the compiler option -language:implicitConversions.
[warn] See the Scaladoc for value scala.language.implicitConversions for a discussion
[warn] why the feature should be explicitly enabled.
[warn]   implicit def stringToInt(s: String): Int = s.length
[warn]                ^
[warn] one warning found
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay