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 scala#3076.
This deprecates it unconditionally, and drops it under -Xsource:2.14.

See scala/bug#7605
  • Loading branch information
eed3si9n authored and adriaanm committed Apr 10, 2018
1 parent ab22def commit 045f9a1
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 20 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.lastOffset, msg("unsupported", ": Unit ="))
else deprecationWarning(in.offset, msg("deprecated", ": Unit ="), "2.13.0")
restype = scalaUnitConstr
blockExpr()
} else {
Expand Down
15 changes: 15 additions & 0 deletions test/files/neg/procedure-deprecation.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
procedure-deprecation.scala:2: warning: procedure syntax is deprecated: instead, add `: Unit =` to explicitly declare `bar`'s return type
def bar {}
^
procedure-deprecation.scala:3: warning: procedure syntax is deprecated: instead, add `: Unit` to explicitly declare `baz`'s return type
def baz
^
procedure-deprecation.scala:4: warning: procedure syntax is deprecated: instead, add `: Unit` to explicitly declare `boo`'s return type
def boo(i: Int, l: Long)
^
procedure-deprecation.scala:5: warning: procedure syntax is deprecated: instead, add `: Unit =` to explicitly declare `boz`'s return type
def boz(i: Int, l: Long) {}
^
error: No warnings can be incurred under -Xfatal-warnings.
four warnings found
one error found
1 change: 1 addition & 0 deletions test/files/neg/procedure-deprecation.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-deprecation -Xfatal-warnings
File renamed without changes.
13 changes: 13 additions & 0 deletions test/files/neg/procedure-removal.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
procedure-removal.scala:2: error: procedure syntax is unsupported: instead, add `: Unit =` to explicitly declare `bar`'s return type
def bar {}
^
procedure-removal.scala:3: error: procedure syntax is unsupported: instead, add `: Unit` to explicitly declare `baz`'s return type
def baz
^
procedure-removal.scala:4: error: procedure syntax is unsupported: instead, add `: Unit` to explicitly declare `boo`'s return type
def boo(i: Int, l: Long)
^
procedure-removal.scala:5: error: procedure syntax is unsupported: instead, add `: Unit =` to explicitly declare `boz`'s return type
def boz(i: Int, l: Long) {}
^
four errors found
1 change: 1 addition & 0 deletions test/files/neg/procedure-removal.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Xsource:2.14
8 changes: 8 additions & 0 deletions test/files/neg/procedure-removal.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
abstract class Foo {
def bar {}
def baz
def boo(i: Int, l: Long)
def boz(i: Int, l: Long) {}
def this(i: Int) { this() } // Don't complain here!
def foz: Unit // Don't complain here!
}
15 changes: 0 additions & 15 deletions test/files/neg/t7605-deprecation.check

This file was deleted.

1 change: 0 additions & 1 deletion test/files/neg/t7605-deprecation.flags

This file was deleted.

0 comments on commit 045f9a1

Please sign in to comment.