Abhijit Sarkar Abhijit Sarkar - 5 months ago 80
Scala Question

Scala Postfix operator warning contradicts with Scaladoc

My code:

val exitStatus = url #> outfile !

new URL("http://www.scala-lang.org/") #> new File("scala-lang.html") !


postfix operator ! should be enabled
[warn] by making the implicit value scala.language.postfixOps visible.
[warn] This can be achieved by adding the import clause 'import scala.language.postfixOps'
[warn] or by setting the compiler option -language:postfixOps.
[warn] See the Scaladoc for value scala.language.postfixOps for a discussion
[warn] why the feature should be explicitly enabled.
[warn] val exitStatus = url #> outfile !
[warn] ^
[warn] one warning found



enter image description here

Keep calm and follow the warning.

import scala.language.postfixOps
val exitStatus = url #> outfile !

And... no warning! :)

The reason for these is so that people new to Scala don't use these by accident and end up more confused about syntax. I'm not sure I agree with this rationale, but it seems to work with my coworkers/friends, so there's definitely something to it.

As an aside here is the Scaladoc page that details all of these. You can also enable these as compiler flags or through build.sbt.

-language:dynamics             # Allow direct or indirect subclasses of scala.Dynamic
-language:existential          # Existential types (besides wildcard types) can be written and inferred
-language:experimental.macros  # Allow macro defintion (besides implementation and application)
-language:higherKinds          # Allow higher-kinded types
-language:implicitConversions  # Allow definition of implicit functions called views
-language:postfixOps           # Allow postfix operator notation, such as `1 to 10 toList'
-language:reflectiveCalls      # Allow reflective access to members of structural types