Skip to content

Commit 1d4d901

Browse files
committed
Deprecate procedure syntax unconditionally
Procedure syntax was deprecated under -Xfuture flag in scala#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 ```
1 parent d93d106 commit 1d4d901

File tree

844 files changed

+1842
-1815
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

844 files changed

+1842
-1815
lines changed

src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,18 +2727,20 @@ self =>
27272727
val vparamss = paramClauses(name, contextBoundBuf.toList, ofCaseClass = false)
27282728
newLineOptWhenFollowedBy(LBRACE)
27292729
var restype = fromWithinReturnType(typedOpt())
2730+
def msg(what: String, instead: String) =
2731+
s"procedure syntax is $what: instead, add `$instead` to explicitly declare `$name`'s return type"
27302732
val rhs =
27312733
if (isStatSep || in.token == RBRACE) {
27322734
if (restype.isEmpty) {
2733-
if (settings.future)
2734-
deprecationWarning(in.lastOffset, s"Procedure syntax is deprecated. Convert procedure `$name` to method by adding `: Unit`.", "2.12.0")
2735+
if (settings.isScala214) syntaxError(in.lastOffset, msg("unsupported", ": Unit"))
2736+
else deprecationWarning(in.lastOffset, msg("deprecated", ": Unit"), "2.13.0")
27352737
restype = scalaUnitConstr
27362738
}
27372739
newmods |= Flags.DEFERRED
27382740
EmptyTree
27392741
} else if (restype.isEmpty && in.token == LBRACE) {
2740-
if (settings.future)
2741-
deprecationWarning(in.offset, s"Procedure syntax is deprecated. Convert procedure `$name` to method by adding `: Unit =`.", "2.12.0")
2742+
if (settings.isScala214) syntaxError(in.offset, msg("unsupported", ": Unit ="))
2743+
else deprecationWarning(in.offset, msg("deprecated", ": Unit ="), "2.13.0")
27422744
restype = scalaUnitConstr
27432745
blockExpr()
27442746
} else {

test/benchmarks/src/main/scala/scala/BitManipulationBenchmark.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class BitManipulationBenchmark {
1818

1919
//////////////////////////////////////////////
2020

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

3131
//////////////////////////////////////////////
3232

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

4343
//////////////////////////////////////////////
4444

45-
@Benchmark def withLoop(bh: Blackhole) {
45+
@Benchmark def withLoop(bh: Blackhole): Unit = {
4646
for (v <- powersOfTwo) {
4747
val leadingZeros = withLoop(v)
4848
bh.consume(leadingZeros)
@@ -61,7 +61,7 @@ class BitManipulationBenchmark {
6161

6262
//////////////////////////////////////////////
6363

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

107107
//////////////////////////////////////////////
108108

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

123123
//////////////////////////////////////////////
124124

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

151151
//////////////////////////////////////////////
152152

153-
@Benchmark def withSumBinSearch(bh: Blackhole) {
153+
@Benchmark def withSumBinSearch(bh: Blackhole): Unit = {
154154
for (v <- powersOfTwo) {
155155
val leadingZeros = withSumBinSearch(v)
156156
// assert(leadingZeros == withLoop(v), s"$leadingZeros != ${withLoop(v)} ($v)")

test/benchmarks/src/main/scala/scala/collection/mutable/OpenHashMapBenchmark.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private object OpenHashMapBenchmark {
5757
var maps: Array[OpenHashMap[K,Int]] = null
5858

5959
@Setup
60-
def threadSetup(params: BenchmarkParams) {
60+
def threadSetup(params: BenchmarkParams): Unit = {
6161
size = params.getParam("size").toInt
6262
val n = math.ceil(minNanosPerInvocation / (nanosPerPut * size)).toInt
6363
_mapEntries = size * n
@@ -66,12 +66,12 @@ private object OpenHashMapBenchmark {
6666
}
6767

6868
@Setup(Level.Iteration)
69-
def iterationSetup {
69+
def iterationSetup: Unit = {
7070
_operations = 0
7171
}
7272

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

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

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

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

134134
/** Load the map with keys from `1` to `size`, removing half of them. */
135135
@Setup
136-
def setup(params: BenchmarkParams) {
136+
def setup(params: BenchmarkParams): Unit = {
137137
val size = params.getParam("size").toInt
138138
_keys = keyBuilder.build(size)
139139
put_remove(map, keys)
@@ -172,7 +172,7 @@ private object OpenHashMapBenchmark {
172172
* @param from lowest index in the range of keys to add
173173
* @param to highest index in the range of keys to add, plus one
174174
*/
175-
private[this] def put[K](map: OpenHashMap[K,Int], keys: KeySeq[K], from: Int, to: Int) {
175+
private[this] def put[K](map: OpenHashMap[K,Int], keys: KeySeq[K], from: Int, to: Int): Unit = {
176176
var i = from
177177
while (i < to) { // using a `for` expression instead adds significant overhead
178178
map.put(keys(i), i)
@@ -190,7 +190,7 @@ private object OpenHashMapBenchmark {
190190
*
191191
* @param keys list of keys to use
192192
*/
193-
private def put_remove[K](map: OpenHashMap[K,Int], keys: KeySeq[K]) {
193+
private def put_remove[K](map: OpenHashMap[K,Int], keys: KeySeq[K]): Unit = {
194194
val blocks = 25 // should be a non-trivial factor of `size`
195195
val size = keys.size
196196
val blockSize: Int = size / blocks
@@ -241,7 +241,7 @@ class OpenHashMapBenchmark {
241241

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

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

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

287287
/** Test putting and removing elements to a growing map of `AnyRef` to `Int`. */
288288
@Benchmark
289-
def put_remove_AnyRef(state: AnyRefBulkPutState) {
289+
def put_remove_AnyRef(state: AnyRefBulkPutState): Unit = {
290290
var i = 0
291291
while (i < state.maps.length) {
292292
put_remove(state.maps(i), state.keys)

test/benchmarks/src/main/scala/scala/collection/mutable/OpenHashMapRunner.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ object OpenHashMapRunner extends JmhRunner {
4646
/** Return the statistics of the given result as a string. */
4747
private[this] def stats(r: Result[_]) = r.getScore + " " + r.getStatistics.getStandardDeviation
4848

49-
50-
def main(args: Array[String]) {
49+
def main(args: Array[String]): Unit = {
5150
import scala.collection.JavaConverters._
52-
51+
5352
val opts = new CommandLineOptions(args: _*)
5453
var builder = new OptionsBuilder().parent(opts).jvmArgsPrepend("-Xmx6000m")
5554
if (!opts.verbosity.hasValue) builder = builder.verbosity(VerboseMode.SILENT)
@@ -95,7 +94,7 @@ object OpenHashMapRunner extends JmhRunner {
9594
}
9695
}
9796

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

101100
val isMemoryUsageDataset = label.endsWith(memoryDatasetQualifier)

test/files/bench/equality/eq.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object eq extends testing.Benchmark {
1919
val obj1 = new Object
2020
val obj2 = new Object
2121

22-
def run() {
22+
def run(): Unit = {
2323
var sum = 0
2424
sum += eqtest(x => if (x == 0) obj1 else obj2, 2000)
2525
sum += eqtest(x => x, 1000)

test/files/bench/equality/eqeq.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object eqeq extends testing.Benchmark {
3131
val obj1 = new Object
3232
val obj2 = new Object
3333

34-
def run() {
34+
def run(): Unit = {
3535
var sum = 0
3636
sum += eqeqtest(x => if (x == 0) obj1 else obj2, 2000)
3737
sum += eqeqtest(x => x, 1000)

test/files/instrumented/InstrumentationTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ package instrumented {
1414

1515
/** Tests if instrumentation itself works correctly */
1616
object Test {
17-
def main(args: Array[String]) {
17+
def main(args: Array[String]): Unit = {
1818
if (scala.tools.partest.utils.Properties.isAvian) {
1919
println("!!!TEST SKIPPED!!!")
2020
println("Instrumentation is not supported on Avian.")

test/files/instrumented/inline-in-constructors/assert_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package instrumented
22

33
object MyPredef {
44
@inline
5-
final def assert(assertion: Boolean, message: => Any) {
5+
final def assert(assertion: Boolean, message: => Any): Unit = {
66
if (!assertion)
77
throw new java.lang.AssertionError("assertion failed: " + message)
88
}

test/files/instrumented/inline-in-constructors/test_3.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import scala.tools.partest.instrumented.Instrumentation._
22
import instrumented._
33

44
object Test {
5-
def main(args: Array[String]) {
5+
def main(args: Array[String]): Unit = {
66
if (scala.tools.partest.utils.Properties.isAvian) {
77
println("!!!TEST SKIPPED!!!")
88
println("Instrumentation is not supported on Avian.")

test/files/instrumented/t6611.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.tools.partest.instrumented.Instrumentation._
22

33
object Test {
4-
def main(args: Array[String]) {
4+
def main(args: Array[String]): Unit = {
55
startProfiling()
66

77
// tests optimization in Cleanup for varargs reference arrays

test/files/jvm/annotations.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Test2 {
99
@throws(classOf[IOException])
1010
def read() = in.read()
1111
}
12-
def run {
12+
def run: Unit = {
1313
val method = classOf[Reader].getMethod("read")
1414
method.getExceptionTypes foreach println
1515
}
@@ -32,7 +32,7 @@ object Test3 {
3232
@Deprecated
3333
def foo: Unit = ()
3434
}
35-
def run {
35+
def run: Unit = {
3636
val method = classOf[Foo].getMethod("foo")
3737
val annotation = method.getAnnotation(classOf[Deprecated])
3838
println(annotation)
@@ -103,15 +103,15 @@ object Test4 {
103103
class Foo10(@SourceAnnotation("on param 1") val name: String)
104104
class Foo11(@(SourceAnnotation @scala.annotation.meta.field)("on param 2") val name: String)
105105
class Foo12(@(SourceAnnotation @scala.annotation.meta.setter)("on param 3") var name: String)
106-
def run {
106+
def run: Unit = {
107107
import java.lang.annotation.Annotation
108108
import java.lang.reflect.AnnotatedElement
109-
def printSourceAnnotation(a: Annotation) {
109+
def printSourceAnnotation(a: Annotation): Unit = {
110110
val ann = a.asInstanceOf[SourceAnnotation]
111111
println("@test.SourceAnnotation(mails=" + ann.mails.deep.mkString("{", ",", "}") +
112112
", value=" + ann.value + ")")
113113
}
114-
def printSourceAnnotations(target: AnnotatedElement) {
114+
def printSourceAnnotations(target: AnnotatedElement): Unit = {
115115
//print SourceAnnotation in a predefined way to insure
116116
// against difference in the JVMs (e.g. Sun's vs IBM's)
117117
val anns = target.getAnnotations()
@@ -121,7 +121,7 @@ object Test4 {
121121
println
122122
}
123123
}
124-
def printParamSourceAnnotations(target: { def getParameterAnnotations(): Array[Array[Annotation]] }) {
124+
def printParamSourceAnnotations(target: { def getParameterAnnotations(): Array[Array[Annotation]] }): Unit = {
125125
val anns = target.getParameterAnnotations().flatten
126126
anns foreach printSourceAnnotation
127127
if (anns.length > 0) {
@@ -171,7 +171,7 @@ object Test5 {
171171
def get = getter.invoke(this).asInstanceOf[Integer].intValue
172172
def set(n: Int) = setter.invoke(this, new Integer(n))
173173
}
174-
def run {
174+
def run: Unit = {
175175
val count = new Count
176176
println(count.get)
177177
count.set(99)
@@ -187,7 +187,7 @@ object Test6 {
187187
@BeanProperty val m: Int = if (prop) 1 else 2
188188
}
189189

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

205205
object Test {
206-
def main(args: Array[String]) {
206+
def main(args: Array[String]): Unit = {
207207
Test2.run
208208
Test3.run // requires the use of -target:jvm-1.5
209209
Test4.run

test/files/jvm/bigints.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
* @author Stephane Micheloud
55
*/
66
object Test {
7-
def main(args: Array[String]) {
7+
def main(args: Array[String]): Unit = {
88
Test_BigInt.runTest()
99
Test_BigDecimal.runTest()
1010
}
1111
}
1212

1313
object Test_BigInt {
14-
def runTest() {
14+
def runTest(): Unit = {
1515
import BigInt._
1616

1717
val x: BigInt = 1
@@ -26,7 +26,7 @@ object Test_BigInt {
2626
}
2727

2828
object Test_BigDecimal {
29-
def runTest() {
29+
def runTest(): Unit = {
3030
import scala.BigDecimal, BigDecimal._
3131

3232
val xi: BigDecimal = 1

test/files/jvm/deprecation/Test_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Test {
2-
def test {
2+
def test: Unit = {
33
val d = new Defs
44
val u = d.i + 1
55
d.i = 2
@@ -14,4 +14,4 @@ class Test {
1414
}
1515
}
1616

17-
object Test { def main(args: Array[String]) { } }
17+
object Test { def main(args: Array[String]): Unit = { } }

test/files/jvm/future-spec/FutureTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ class FutureTests extends MinimalScalaTest {
587587

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

0 commit comments

Comments
 (0)