运行某个Scala脚本会显示以下警告:
warning: there were 1 deprecation warnings; re-run with -deprecation for details我该怎么做?
是的,我有RTFM,但是它所说的(用-分隔编译器参数和其他参数)不起作用。
发布于 2013-04-26 05:27:31
只有Scala解释器(用于执行脚本时)支持shebang语法('#!')。scalac和scala REPL都不支持它。有关问题跟踪,请参阅here。
请参阅下面的内容,以获得与shebang一起工作的答案。
你可能想要考虑什么,而不是使用“#!”
为了能够在REPL和解释器中使用一个文件(也可以作为源代码,例如,如果它是一个有效的类),你应该完全放弃shebang头文件,并可能添加一个启动器脚本(例如,有一个可执行的'foo‘启动'scala foo.scala')。
让我们将'foo.scala‘定义为以下一行代码:
case class NoParens // <-- case classes w/o () are deprecated这将适用于解释器:
$ scala foo.scala...the编译器
$ scalac foo.scala..。和REPL:
$ scala -i foo.scala
// or:
$ scala
scala> :load foo.scala以上所有内容都会给出你问题中的模糊的弃用警告。
对于通过'scala‘可执行文件执行的脚本,以及通过'scalac’编译的脚本,您所要做的就是在命令行中添加一个'-deprecation‘参数:
$ scala -deprecation foo.scala
// or:
$ scalac -deprecation foo.scala两者现在都会给出详细的弃用警告(‘-feature’也是如此)。
REPL为您提供了两种选择: 1)如上所述添加-deprecation参数(留给读者的练习) 2)在REPL中使用':warnings‘,如下所示:
$ scala -i foo.scala
Loading foo.scala...
warning: there were 1 deprecation warnings; re-run with -deprecation for details
defined class NoParens
Welcome to Scala etc...
scala> :warnings
<console>:7: warning: case classes without a parameter list have been deprecated;
use either case objects or case classes with `()' as parameter list.
case class NoParens // <-- case classes without () are deprecated
^
scala>不用说,在REPL中使用':load‘也是如此。
将“-deprecation”与“#!”一起使用
正如我所承诺的,这里有一个使用shebang语法的秘诀。我自己并不经常使用它,所以欢迎评论:
#!/bin/sh
exec scala $0 $@
!#
case class NoParens // <-- case classes w/o () are deprecated这将为您提供一个神秘的警告:
$ ./foo.scala
warning: there were 1 deprecation warnings; re-run with -deprecation for details
one warning found要收到所有的警告,只需在'exec scala‘后面添加一个'-deprecation’,如下所示:
#!/bin/sh
exec scala -deprecation $0 $@
!#
// etc...这将产生所需的“警告:没有参数列表的案例类已被弃用”等...
好了,这就差不多了。360度的弃用;-)
发布于 2013-04-24 16:54:42
将脚本转换为应用程序:
#! ... !#位(用于Unix/Mac上的可执行脚本)object Foo extends App { ... }中的所有内容
然后使用以下命令进行编译
scalac -deprecation filename.scala以查看详细的弃用警告。
发布于 2013-04-25 09:10:08
您收到的警告是编译器错误。Scala有两个编译器,很可能会从脚本中调用: scalac和fsc。找到脚本调用其中一个参数的位置,并编辑编译器调用以包含标志-deprecation。
例如:
scalac -arg1 -arg2 big/long/path/*.scala other/path/*.scala变成了
scalac -deprecation -arg1 -arg2 big/long/path/*.scala other/path/*.scalahttps://stackoverflow.com/questions/16187616
复制相似问题