Skip to content

Commit

Permalink
Deprecate procedure syntax unconditionally
Browse files Browse the repository at this point in the history
Procedure syntax was deprecated under -Xfuture flag in #3076.
This deprecates it unconditionally, and drops it under -Xsource:2.14.
See scala/bug#7605

To update the tests, this drops procedure syntax from test/ using ScalaFix

```
$ coursier launch ch.epfl.scala:scalafix-cli_2.12.3:0.5.3 -- -r ProcedureSyntax test
$ coursier launch ch.epfl.scala:scalafix-cli_2.12.4:0.5.10 -- -r ExplicitUnit test
```
  • Loading branch information
eed3si9n committed Apr 25, 2018
1 parent d93d106 commit 1d4d901
Show file tree
Hide file tree
Showing 844 changed files with 1,842 additions and 1,815 deletions.
10 changes: 6 additions & 4 deletions src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2727,18 +2727,20 @@ self =>
val vparamss = paramClauses(name, contextBoundBuf.toList, ofCaseClass = false)
newLineOptWhenFollowedBy(LBRACE)
var restype = fromWithinReturnType(typedOpt())
def msg(what: String, instead: String) =
s"procedure syntax is $what: instead, add `$instead` to explicitly declare `$name`'s return type"
val rhs =
if (isStatSep || in.token == RBRACE) {
if (restype.isEmpty) {
if (settings.future)
deprecationWarning(in.lastOffset, s"Procedure syntax is deprecated. Convert procedure `$name` to method by adding `: Unit`.", "2.12.0")
if (settings.isScala214) syntaxError(in.lastOffset, msg("unsupported", ": Unit"))
else deprecationWarning(in.lastOffset, msg("deprecated", ": Unit"), "2.13.0")
restype = scalaUnitConstr
}
newmods |= Flags.DEFERRED
EmptyTree
} else if (restype.isEmpty && in.token == LBRACE) {
if (settings.future)
deprecationWarning(in.offset, s"Procedure syntax is deprecated. Convert procedure `$name` to method by adding `: Unit =`.", "2.12.0")
if (settings.isScala214) syntaxError(in.offset, msg("unsupported", ": Unit ="))
else deprecationWarning(in.offset, msg("deprecated", ": Unit ="), "2.13.0")
restype = scalaUnitConstr
blockExpr()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BitManipulationBenchmark {

//////////////////////////////////////////////

@Benchmark def withIntegerBitCount(bh: Blackhole) {
@Benchmark def withIntegerBitCount(bh: Blackhole): Unit = {
for (v <- powersOfTwo) {
val leadingZeros = withIntegerBitCount(v)
// assert (leadingZeros == withLoop(v), s"$leadingZeros != ${withLoop(v)} ($v)")
Expand All @@ -30,7 +30,7 @@ class BitManipulationBenchmark {

//////////////////////////////////////////////

@Benchmark def withIntegerNumberOfLeadingZeros(bh: Blackhole) {
@Benchmark def withIntegerNumberOfLeadingZeros(bh: Blackhole): Unit = {
for (v <- powersOfTwo) {
val leadingZeros = withIntegerNumberOfLeadingZeros(v)
// assert (leadingZeros == withLoop(v), s"$leadingZeros != ${withLoop(v)} ($v)")
Expand All @@ -42,7 +42,7 @@ class BitManipulationBenchmark {

//////////////////////////////////////////////

@Benchmark def withLoop(bh: Blackhole) {
@Benchmark def withLoop(bh: Blackhole): Unit = {
for (v <- powersOfTwo) {
val leadingZeros = withLoop(v)
bh.consume(leadingZeros)
Expand All @@ -61,7 +61,7 @@ class BitManipulationBenchmark {

//////////////////////////////////////////////

@Benchmark def withMatch(bh: Blackhole) {
@Benchmark def withMatch(bh: Blackhole): Unit = {
for (v <- powersOfTwo) {
val leadingZeros = withMatch(v)
// assert (leadingZeros == withLoop(v), s"$leadingZeros != ${withLoop(v)} ($v)")
Expand Down Expand Up @@ -106,7 +106,7 @@ class BitManipulationBenchmark {

//////////////////////////////////////////////

@Benchmark def with2DeBruijn(bh: Blackhole) {
@Benchmark def with2DeBruijn(bh: Blackhole): Unit = {
for (v <- powersOfTwo) {
val leadingZeros = with2DeBruijn(v)
// assert (leadingZeros == withLoop(v), s"$leadingZeros != ${withLoop(v)} ($v)")
Expand All @@ -122,7 +122,7 @@ class BitManipulationBenchmark {

//////////////////////////////////////////////

@Benchmark def withBinSearch(bh: Blackhole) {
@Benchmark def withBinSearch(bh: Blackhole): Unit = {
for (v <- powersOfTwo) {
val leadingZeros = withBinSearch(v)
// assert (leadingZeros == withLoop(v), s"$leadingZeros != ${withLoop(v)} ($v)")
Expand Down Expand Up @@ -150,7 +150,7 @@ class BitManipulationBenchmark {

//////////////////////////////////////////////

@Benchmark def withSumBinSearch(bh: Blackhole) {
@Benchmark def withSumBinSearch(bh: Blackhole): Unit = {
for (v <- powersOfTwo) {
val leadingZeros = withSumBinSearch(v)
// assert(leadingZeros == withLoop(v), s"$leadingZeros != ${withLoop(v)} ($v)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private object OpenHashMapBenchmark {
var maps: Array[OpenHashMap[K,Int]] = null

@Setup
def threadSetup(params: BenchmarkParams) {
def threadSetup(params: BenchmarkParams): Unit = {
size = params.getParam("size").toInt
val n = math.ceil(minNanosPerInvocation / (nanosPerPut * size)).toInt
_mapEntries = size * n
Expand All @@ -66,12 +66,12 @@ private object OpenHashMapBenchmark {
}

@Setup(Level.Iteration)
def iterationSetup {
def iterationSetup: Unit = {
_operations = 0
}

@Setup(Level.Invocation)
def setup(params: IterationParams) {
def setup(params: IterationParams): Unit = {
for (i <- 0 until maps.length) maps(i) = new OpenHashMap[K,Int](size)

if (params.getType == IterationType.MEASUREMENT) {
Expand All @@ -81,7 +81,7 @@ private object OpenHashMapBenchmark {
}

@TearDown(Level.Iteration)
def iterationTeardown(params: IterationParams) {
def iterationTeardown(params: IterationParams): Unit = {
if (params.getType == IterationType.MEASUREMENT) {
// limit to smaller cases to avoid OOM
_memory =
Expand All @@ -108,7 +108,7 @@ private object OpenHashMapBenchmark {

/** Load the map with keys from `1` to `size`. */
@Setup
def setup(params: BenchmarkParams) {
def setup(params: BenchmarkParams): Unit = {
val size = params.getParam("size").toInt
_keys = keyBuilder.build(size)
put(map, keys, 0, size)
Expand All @@ -133,7 +133,7 @@ private object OpenHashMapBenchmark {

/** Load the map with keys from `1` to `size`, removing half of them. */
@Setup
def setup(params: BenchmarkParams) {
def setup(params: BenchmarkParams): Unit = {
val size = params.getParam("size").toInt
_keys = keyBuilder.build(size)
put_remove(map, keys)
Expand Down Expand Up @@ -172,7 +172,7 @@ private object OpenHashMapBenchmark {
* @param from lowest index in the range of keys to add
* @param to highest index in the range of keys to add, plus one
*/
private[this] def put[K](map: OpenHashMap[K,Int], keys: KeySeq[K], from: Int, to: Int) {
private[this] def put[K](map: OpenHashMap[K,Int], keys: KeySeq[K], from: Int, to: Int): Unit = {
var i = from
while (i < to) { // using a `for` expression instead adds significant overhead
map.put(keys(i), i)
Expand All @@ -190,7 +190,7 @@ private object OpenHashMapBenchmark {
*
* @param keys list of keys to use
*/
private def put_remove[K](map: OpenHashMap[K,Int], keys: KeySeq[K]) {
private def put_remove[K](map: OpenHashMap[K,Int], keys: KeySeq[K]): Unit = {
val blocks = 25 // should be a non-trivial factor of `size`
val size = keys.size
val blockSize: Int = size / blocks
Expand Down Expand Up @@ -241,7 +241,7 @@ class OpenHashMapBenchmark {

/** Test putting elements to a map of `Int` to `Int`. */
@Benchmark
def put_Int(state: IntBulkPutState) {
def put_Int(state: IntBulkPutState): Unit = {
var i = 0
while (i < state.maps.length) {
put(state.maps(i), state.keys)
Expand All @@ -251,7 +251,7 @@ class OpenHashMapBenchmark {

/** Test putting and removing elements to a growing map of `Int` to `Int`. */
@Benchmark
def put_remove_Int(state: IntBulkPutState) {
def put_remove_Int(state: IntBulkPutState): Unit = {
var i = 0
while (i < state.maps.length) {
put_remove(state.maps(i), state.keys)
Expand All @@ -276,7 +276,7 @@ class OpenHashMapBenchmark {

/** Test putting elements to a map of `AnyRef` to `Int`. */
@Benchmark
def put_AnyRef(state: AnyRefBulkPutState) {
def put_AnyRef(state: AnyRefBulkPutState): Unit = {
var i = 0
while (i < state.maps.length) {
put(state.maps(i), state.keys)
Expand All @@ -286,7 +286,7 @@ class OpenHashMapBenchmark {

/** Test putting and removing elements to a growing map of `AnyRef` to `Int`. */
@Benchmark
def put_remove_AnyRef(state: AnyRefBulkPutState) {
def put_remove_AnyRef(state: AnyRefBulkPutState): Unit = {
var i = 0
while (i < state.maps.length) {
put_remove(state.maps(i), state.keys)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ object OpenHashMapRunner extends JmhRunner {
/** Return the statistics of the given result as a string. */
private[this] def stats(r: Result[_]) = r.getScore + " " + r.getStatistics.getStandardDeviation


def main(args: Array[String]) {
def main(args: Array[String]): Unit = {
import scala.collection.JavaConverters._

val opts = new CommandLineOptions(args: _*)
var builder = new OptionsBuilder().parent(opts).jvmArgsPrepend("-Xmx6000m")
if (!opts.verbosity.hasValue) builder = builder.verbosity(VerboseMode.SILENT)
Expand Down Expand Up @@ -95,7 +94,7 @@ object OpenHashMapRunner extends JmhRunner {
}
}

private[this] def outputDataset(f: PrintWriter, label: String, dataset: Iterable[RunResult]) {
private[this] def outputDataset(f: PrintWriter, label: String, dataset: Iterable[RunResult]): Unit = {
f.println(s"# [$label]")

val isMemoryUsageDataset = label.endsWith(memoryDatasetQualifier)
Expand Down
2 changes: 1 addition & 1 deletion test/files/bench/equality/eq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object eq extends testing.Benchmark {
val obj1 = new Object
val obj2 = new Object

def run() {
def run(): Unit = {
var sum = 0
sum += eqtest(x => if (x == 0) obj1 else obj2, 2000)
sum += eqtest(x => x, 1000)
Expand Down
2 changes: 1 addition & 1 deletion test/files/bench/equality/eqeq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object eqeq extends testing.Benchmark {
val obj1 = new Object
val obj2 = new Object

def run() {
def run(): Unit = {
var sum = 0
sum += eqeqtest(x => if (x == 0) obj1 else obj2, 2000)
sum += eqeqtest(x => x, 1000)
Expand Down
2 changes: 1 addition & 1 deletion test/files/instrumented/InstrumentationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package instrumented {

/** Tests if instrumentation itself works correctly */
object Test {
def main(args: Array[String]) {
def main(args: Array[String]): Unit = {
if (scala.tools.partest.utils.Properties.isAvian) {
println("!!!TEST SKIPPED!!!")
println("Instrumentation is not supported on Avian.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package instrumented

object MyPredef {
@inline
final def assert(assertion: Boolean, message: => Any) {
final def assert(assertion: Boolean, message: => Any): Unit = {
if (!assertion)
throw new java.lang.AssertionError("assertion failed: " + message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import scala.tools.partest.instrumented.Instrumentation._
import instrumented._

object Test {
def main(args: Array[String]) {
def main(args: Array[String]): Unit = {
if (scala.tools.partest.utils.Properties.isAvian) {
println("!!!TEST SKIPPED!!!")
println("Instrumentation is not supported on Avian.")
Expand Down
2 changes: 1 addition & 1 deletion test/files/instrumented/t6611.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import scala.tools.partest.instrumented.Instrumentation._

object Test {
def main(args: Array[String]) {
def main(args: Array[String]): Unit = {
startProfiling()

// tests optimization in Cleanup for varargs reference arrays
Expand Down
18 changes: 9 additions & 9 deletions test/files/jvm/annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Test2 {
@throws(classOf[IOException])
def read() = in.read()
}
def run {
def run: Unit = {
val method = classOf[Reader].getMethod("read")
method.getExceptionTypes foreach println
}
Expand All @@ -32,7 +32,7 @@ object Test3 {
@Deprecated
def foo: Unit = ()
}
def run {
def run: Unit = {
val method = classOf[Foo].getMethod("foo")
val annotation = method.getAnnotation(classOf[Deprecated])
println(annotation)
Expand Down Expand Up @@ -103,15 +103,15 @@ object Test4 {
class Foo10(@SourceAnnotation("on param 1") val name: String)
class Foo11(@(SourceAnnotation @scala.annotation.meta.field)("on param 2") val name: String)
class Foo12(@(SourceAnnotation @scala.annotation.meta.setter)("on param 3") var name: String)
def run {
def run: Unit = {
import java.lang.annotation.Annotation
import java.lang.reflect.AnnotatedElement
def printSourceAnnotation(a: Annotation) {
def printSourceAnnotation(a: Annotation): Unit = {
val ann = a.asInstanceOf[SourceAnnotation]
println("@test.SourceAnnotation(mails=" + ann.mails.deep.mkString("{", ",", "}") +
", value=" + ann.value + ")")
}
def printSourceAnnotations(target: AnnotatedElement) {
def printSourceAnnotations(target: AnnotatedElement): Unit = {
//print SourceAnnotation in a predefined way to insure
// against difference in the JVMs (e.g. Sun's vs IBM's)
val anns = target.getAnnotations()
Expand All @@ -121,7 +121,7 @@ object Test4 {
println
}
}
def printParamSourceAnnotations(target: { def getParameterAnnotations(): Array[Array[Annotation]] }) {
def printParamSourceAnnotations(target: { def getParameterAnnotations(): Array[Array[Annotation]] }): Unit = {
val anns = target.getParameterAnnotations().flatten
anns foreach printSourceAnnotation
if (anns.length > 0) {
Expand Down Expand Up @@ -171,7 +171,7 @@ object Test5 {
def get = getter.invoke(this).asInstanceOf[Integer].intValue
def set(n: Int) = setter.invoke(this, new Integer(n))
}
def run {
def run: Unit = {
val count = new Count
println(count.get)
count.set(99)
Expand All @@ -187,7 +187,7 @@ object Test6 {
@BeanProperty val m: Int = if (prop) 1 else 2
}

def run {
def run: Unit = {
val c = new C("bob")
c.setText("dylan")
println(c.getText())
Expand All @@ -203,7 +203,7 @@ object Test6 {
class A3345(@volatile private var i:Int)

object Test {
def main(args: Array[String]) {
def main(args: Array[String]): Unit = {
Test2.run
Test3.run // requires the use of -target:jvm-1.5
Test4.run
Expand Down
6 changes: 3 additions & 3 deletions test/files/jvm/bigints.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* @author Stephane Micheloud
*/
object Test {
def main(args: Array[String]) {
def main(args: Array[String]): Unit = {
Test_BigInt.runTest()
Test_BigDecimal.runTest()
}
}

object Test_BigInt {
def runTest() {
def runTest(): Unit = {
import BigInt._

val x: BigInt = 1
Expand All @@ -26,7 +26,7 @@ object Test_BigInt {
}

object Test_BigDecimal {
def runTest() {
def runTest(): Unit = {
import scala.BigDecimal, BigDecimal._

val xi: BigDecimal = 1
Expand Down
4 changes: 2 additions & 2 deletions test/files/jvm/deprecation/Test_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Test {
def test {
def test: Unit = {
val d = new Defs
val u = d.i + 1
d.i = 2
Expand All @@ -14,4 +14,4 @@ class Test {
}
}

object Test { def main(args: Array[String]) { } }
object Test { def main(args: Array[String]): Unit = { } }
2 changes: 1 addition & 1 deletion test/files/jvm/future-spec/FutureTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ class FutureTests extends MinimalScalaTest {

"fold mutable zeroes safely" in {
import scala.collection.mutable.ArrayBuffer
def test(testNumber: Int) {
def test(testNumber: Int): Unit = {
val fs = (0 to 1000) map (i => Future(i))
val f = Future.foldLeft(fs)(ArrayBuffer.empty[AnyRef]) {
case (l, i) if i % 2 == 0 => l += i.asInstanceOf[AnyRef]
Expand Down

0 comments on commit 1d4d901

Please sign in to comment.