如何使用-deprecation重新运行scala脚本?

如何使用-deprecation重新运行scala脚本?,scala,Scala,运行某个Scala脚本会发出以下警告: warning: there were 1 deprecation warnings; re-run with -deprecation for details $ ./foo.scala warning: there were 1 deprecation warnings; re-run with -deprecation for details one warning found 我该怎么做 是的,我有RTFM,但它所说的用-分隔编译器参数和其他参

运行某个Scala脚本会发出以下警告:

warning: there were 1 deprecation warnings; re-run with -deprecation for details
$ ./foo.scala
warning: there were 1 deprecation warnings; re-run with -deprecation for details
one warning found
我该怎么做


是的,我有RTFM,但它所说的用-分隔编译器参数和其他参数不起作用。

将脚本转换为应用程序:

删除任何!顶部的位这用于Unix/Mac上的可执行脚本 将所有内容包装到对象Foo扩展应用程序{…} 然后用

scalac -deprecation filename.scala

要查看详细的弃用警告。

请将脚本转换为应用程序:

删除任何!顶部的位这用于Unix/Mac上的可执行脚本 将所有内容包装到对象Foo扩展应用程序{…} 然后用

scalac -deprecation filename.scala

查看详细的弃用警告。

您收到的警告是编译器错误。Scala有两个可能从脚本调用的编译器:scalac和fsc。查找脚本调用其中一个的位置,并编辑编译器调用以包含标志-deprecation

例如

变成

scalac -deprecation -arg1 -arg2 big/long/path/*.scala other/path/*.scala

您收到的警告是编译器错误。Scala有两个可能从脚本调用的编译器:scalac和fsc。查找脚本调用其中一个的位置,并编辑编译器调用以包含标志-deprecation

例如

变成

scalac -deprecation -arg1 -arg2 big/long/path/*.scala other/path/*.scala

只有用于执行脚本的Scala解释器才支持shebang语法“!”。 scalac和scala REPL都不支持它。有关问题跟踪,请参阅

请参阅下面的答案,它适用于shebang

你可能想考虑而不是使用“!” 为了能够在REPL和解释器中同时使用文件,并且可能还将其用作源代码,例如,如果它是一个有效类,那么您应该完全放弃shebang头,并可能添加一个启动程序脚本,例如,有一个启动“scala foo.scala”的可执行文件“foo”

让我们将“foo.scala”定义为以下一行:

case class NoParens // <-- case classes w/o () are deprecated
…编译器

$ 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>
#!/bin/sh
exec scala -deprecation $0 $@
!#

// etc...
要获得您的警告,只需在“exec scala”之后添加一个“-deprecation”,如下所示:

$ 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>
#!/bin/sh
exec scala -deprecation $0 $@
!#

// etc...
这将产生所需的“警告:没有参数列表的案例类已被弃用”等


好吧,这就够了。360°倾斜度-

只有用于执行脚本的Scala解释器才支持shebang语法“!”。 scalac和scala REPL都不支持它。有关问题跟踪,请参阅

请参阅下面的答案,它适用于shebang

你可能想考虑而不是使用“!” 为了能够在REPL和解释器中同时使用文件,并且可能还将其用作源代码,例如,如果它是一个有效类,那么您应该完全放弃shebang头,并可能添加一个启动程序脚本,例如,有一个启动“scala foo.scala”的可执行文件“foo”

让我们将“foo.scala”定义为以下一行:

case class NoParens // <-- case classes w/o () are deprecated
…编译器

$ 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>
#!/bin/sh
exec scala -deprecation $0 $@
!#

// etc...
要获得您的警告,只需在“exec scala”之后添加一个“-deprecation”,如下所示:

$ 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>
#!/bin/sh
exec scala -deprecation $0 $@
!#

// etc...
这将产生所需的“警告:没有参数列表的案例类已被弃用”等


好吧,这就够了。360°倾斜度-

脚本没有直接调用它们中的任何一个。它在呼叫scala,scala解释器。这就是scala脚本的执行方式。脚本不会直接调用它们中的任何一个。它在呼叫scala,scala解释器。这就是scala脚本的执行方式。当然,原因是脚本的名称总是排在第一位,因此不能在脚本的命令行上指定编译器参数。您必须在脚本中指定它们。原因当然是脚本的名称总是排在第一位,因此您不能在脚本的命令行中指定编译器参数。您必须在脚本中指定它们。