Skip to content

Commit 8601843

Browse files
eed3si9nadriaanm
authored andcommitted
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
1 parent 6ff3fac commit 8601843

10 files changed

+48
-20
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/files/neg/macro-deprecate-idents.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ macro-deprecate-idents.scala:50: error: macro is now a reserved word; usage as a
4949
macro-deprecate-idents.scala:55: error: macro is now a reserved word; usage as an identifier is disallowed
5050
def macro = 2
5151
^
52+
macro-deprecate-idents.scala:55: warning: procedure syntax is deprecated: instead, add `: Unit` to explicitly declare `<error>`'s return type
53+
def macro = 2
54+
^
5255
macro-deprecate-idents.scala:3: error: '=' expected but '}' found.
5356
}
5457
^
@@ -64,4 +67,5 @@ macro-deprecate-idents.scala:45: error: '{' expected but '}' found.
6467
macro-deprecate-idents.scala:52: error: ')' expected but '}' found.
6568
}
6669
^
70+
one warning found
6771
22 errors found
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
procedure-deprecation.scala:2: warning: procedure syntax is deprecated: instead, add `: Unit =` to explicitly declare `bar`'s return type
2+
def bar {}
3+
^
4+
procedure-deprecation.scala:3: warning: procedure syntax is deprecated: instead, add `: Unit` to explicitly declare `baz`'s return type
5+
def baz
6+
^
7+
procedure-deprecation.scala:4: warning: procedure syntax is deprecated: instead, add `: Unit` to explicitly declare `boo`'s return type
8+
def boo(i: Int, l: Long)
9+
^
10+
procedure-deprecation.scala:5: warning: procedure syntax is deprecated: instead, add `: Unit =` to explicitly declare `boz`'s return type
11+
def boz(i: Int, l: Long) {}
12+
^
13+
error: No warnings can be incurred under -Xfatal-warnings.
14+
four warnings found
15+
one error found
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-deprecation -Xfatal-warnings
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
procedure-removal.scala:2: error: procedure syntax is unsupported: instead, add `: Unit =` to explicitly declare `bar`'s return type
2+
def bar {}
3+
^
4+
procedure-removal.scala:3: error: procedure syntax is unsupported: instead, add `: Unit` to explicitly declare `baz`'s return type
5+
def baz
6+
^
7+
procedure-removal.scala:4: error: procedure syntax is unsupported: instead, add `: Unit` to explicitly declare `boo`'s return type
8+
def boo(i: Int, l: Long)
9+
^
10+
procedure-removal.scala:5: error: procedure syntax is unsupported: instead, add `: Unit =` to explicitly declare `boz`'s return type
11+
def boz(i: Int, l: Long) {}
12+
^
13+
four errors found
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xsource:2.14
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
abstract class Foo {
2+
def bar {}
3+
def baz
4+
def boo(i: Int, l: Long)
5+
def boz(i: Int, l: Long) {}
6+
def this(i: Int) { this() } // Don't complain here!
7+
def foz: Unit // Don't complain here!
8+
}

test/files/neg/t7605-deprecation.check

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/files/neg/t7605-deprecation.flags

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)