From bc475036c4cae5e9534ee3f9985e4e7a848e4b67 Mon Sep 17 00:00:00 2001 From: Simon Ochsenreither Date: Sun, 8 Sep 2013 16:38:52 +0200 Subject: SI-7605 Deprecate procedure syntax This commit covers three cases: - constructor definitions (def this {...}) - concrete method definitions (def foo {...}) - abstract method declarations (def foo) The deprecation is currently hidden behind -Xfuture pending IDE support for migrating users from procedures to methods. --- src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 10 +++++++++- test/files/neg/t7605-deprecation.check | 12 ++++++++++++ test/files/neg/t7605-deprecation.flags | 1 + test/files/neg/t7605-deprecation.scala | 5 +++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/files/neg/t7605-deprecation.check create mode 100644 test/files/neg/t7605-deprecation.flags create mode 100644 test/files/neg/t7605-deprecation.scala diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 1d5f35b7d6..07938ec3df 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -2512,7 +2512,11 @@ self => val vparamss = paramClauses(nme.CONSTRUCTOR, classContextBounds map (_.duplicate), ofCaseClass = false) newLineOptWhenFollowedBy(LBRACE) val rhs = in.token match { - case LBRACE => atPos(in.offset) { constrBlock(vparamss) } + case LBRACE => { + if (settings.future) + deprecationWarning(in.offset, "Procedure syntax is deprecated. Convert procedure to method by adding `: Unit =`.") + atPos(in.offset) { constrBlock(vparamss) } + } case _ => accept(EQUALS) ; atPos(in.offset) { constrExpr(vparamss) } } DefDef(mods, nme.CONSTRUCTOR, List(), vparamss, TypeTree(), rhs) @@ -2538,10 +2542,14 @@ self => var restype = fromWithinReturnType(typedOpt()) val rhs = if (isStatSep || in.token == RBRACE) { + if (settings.future) + deprecationWarning(in.lastOffset, "Procedure syntax is deprecated. Convert procedure to method by adding `: Unit`.") if (restype.isEmpty) restype = scalaUnitConstr newmods |= Flags.DEFERRED EmptyTree } else if (restype.isEmpty && in.token == LBRACE) { + if (settings.future) + deprecationWarning(in.offset, "Procedure syntax is deprecated. Convert procedure to method by adding `: Unit =`.") restype = scalaUnitConstr blockExpr() } else { diff --git a/test/files/neg/t7605-deprecation.check b/test/files/neg/t7605-deprecation.check new file mode 100644 index 0000000000..9c466c058c --- /dev/null +++ b/test/files/neg/t7605-deprecation.check @@ -0,0 +1,12 @@ +t7605-deprecation.scala:2: warning: Procedure syntax is deprecated. Convert procedure to method by adding `: Unit =`. + def this(i: Int) { this() } + ^ +t7605-deprecation.scala:3: warning: Procedure syntax is deprecated. Convert procedure to method by adding `: Unit =`. + def bar {} + ^ +t7605-deprecation.scala:4: warning: Procedure syntax is deprecated. Convert procedure to method by adding `: Unit`. + def baz + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/test/files/neg/t7605-deprecation.flags b/test/files/neg/t7605-deprecation.flags new file mode 100644 index 0000000000..0a7cb7d202 --- /dev/null +++ b/test/files/neg/t7605-deprecation.flags @@ -0,0 +1 @@ +-deprecation -Xfuture -Xfatal-warnings diff --git a/test/files/neg/t7605-deprecation.scala b/test/files/neg/t7605-deprecation.scala new file mode 100644 index 0000000000..4a7dcd26d6 --- /dev/null +++ b/test/files/neg/t7605-deprecation.scala @@ -0,0 +1,5 @@ +abstract class Foo { + def this(i: Int) { this() } + def bar {} + def baz +} \ No newline at end of file -- cgit v1.2.3