3

My code: val exitStatus = url #> outfile !

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

Warning:

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

WTF???

Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219

1 Answers1

21

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
Alec
  • 31,829
  • 7
  • 67
  • 114
  • 2
    I know how to get rid of the warning (should've mentioned in my post) but you'd think that the Scaladoc should mention that the example they used would generate a warning, or the compiler would be smarter. I'll accept your answer though just for the keep calm image :) – Abhijit Sarkar Aug 23 '16 at 06:28
  • @AbhijitSarkar I agree. :) – Alec Aug 23 '16 at 06:28
  • In response to your update listing the SBT options, the corresponding line in `build.sbt` is `scalacOptions += "-feature"`. That's how I got the warning details. – Abhijit Sarkar Aug 23 '16 at 06:36
  • thanks a lot @AbhijitSarkar for asking this question, for long time I was stuck with the same warning everytime I tried to download something using scala and thanks Alec for the solution. – Aamir Aug 23 '16 at 06:38
  • Here's a guess: the Scaladoc was written before the deprecation of postfix operators, and nobody has filed a bug yet. – Jörg W Mittag Aug 23 '16 at 20:46