3

For example, when I try to run:

import scala.concurrent.duration._
Await.result(f, 1 seconds)

I get the error:

postfix operator seconds needs to be enabled

How do I do that?
Why do I need that step when I already included the import?


See also - Other question for a previous scala version with different error message covering a similar case but with an ! operator for working with files, but this does not ask the general quesion of how to disable postfix operators, or answer the question of how to use scala.concurrent.duration.

Jethro
  • 3,029
  • 3
  • 27
  • 56
  • Possible duplicate of [Scala Postfix operator warning contradicts with Scaladoc](https://stackoverflow.com/questions/39093695/scala-postfix-operator-warning-contradicts-with-scaladoc) – Robin Green Aug 19 '19 at 17:04
  • I believe this is seperate as this question has a different error message, and is for a different scala version. It is also a compile error, not a warning. People searching with the same issue as this question (the deprecated code is commonly used in official examples, and many tutorials use it without showing the imports) will not directly find the other answer, as it is for `#> outfile` not `postfix operator seconds`. The title of this is a clear question on how to achieve a task, plus a "why is it that way" question. Whereas the other is asking about a documentation discrepency. – Jethro Aug 19 '19 at 19:44

1 Answers1

9

Some of Scalas modular language features need enabling.
Enabling can just be done by using the appropriate import.
In this case it's:

import scala.language.postfixOps
Jethro
  • 3,029
  • 3
  • 27
  • 56
  • 4
    I think this is a new requirement introduced in Scala 2.13 (because postfixOps are being removed, you now need to opt-in). – Thilo Aug 19 '19 at 14:28
  • 1
    Remember that there are reasons why those operators are disabled. The documentation of that language flag explains it all. You should quote that, or at least say what I said and put a link to the documentation. – Luis Miguel Mejía Suárez Aug 19 '19 at 14:29
  • This is what the error message says. It's worth adding that what is enabled is the syntax, not the conversion itself. Also, there's nothing special about the language import; you could `implicit def foo: scala.languageFeature.postfixOps = ???` – som-snytt Aug 19 '19 at 15:53
  • is there a way to do this command line? – Eugene Aug 19 '22 at 08:22