2016-08-23 1 views
1

私のコードと矛盾: val exitStatus = url #> outfile !Scalaの後置演算子の警告がScaladoc

scala.sys.processnew 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 

WTF?

+0

私は矛盾があるとは言いません。暗黙的に後置記法が使用されていますが、ドキュメントに*印を付ける必要があります*。 –

+0

@YuvalItzchakov正確に私のポイント。アレクの返答に対する私のコメントを参照してください。 –

答えて

5

enter image description here

平静そして続行警告に従ってください。

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

...警告なし! :)

これらの理由は、Scalaの新しいユーザーがこれらを偶然使用して構文が混乱するためです。私はこの根拠に同意するのかどうかはわかりませんが、それは私の同僚/友人とうまくいくようです。だから間違いなく何かがあります。余談hereとして


これらのすべての詳細をScaladocページです。コンパイラフラグとして、または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 
+0

私は警告を取り除く方法を知っていますが(私の記事で言及しておくべきですが)、Scaladocは、使用した例が警告を生成したり、コンパイラがよりスマートになると言及する必要があると考えるでしょう。私はあなたの答えを受け入れるでしょうが、ただ静かなイメージを保つためです:) –

+0

@AbhijitSarkar私は同意します。 :) – Alec

+0

SBTオプションをリストアップした更新に応じて、 'build.sbt'の対応する行は' scalacOptions + = "-feature" 'です。それが私が警告の詳細を得た方法です。 –

関連する問題