Skip to content

Commit

Permalink
Deprecate old-style constructor syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Dec 11, 2019
1 parent 4ae0e92 commit 5d7314c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Expand Up @@ -2749,12 +2749,13 @@ self =>
def funDefOrDcl(start : Int, mods: Modifiers): Tree = {
in.nextToken()
if (in.token == THIS) {
def missingEquals() = deprecationWarning(in.lastOffset, "procedure syntax is deprecated for constructors: add `=`, as in method definition", "2.13.2")
atPos(start, in.skipToken()) {
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 _ => accept(EQUALS) ; atPos(in.offset) { constrExpr(vparamss) }
case LBRACE if !currentRun.isScala214 => missingEquals(); atPos(in.offset) { constrBlock(vparamss) }
case _ => accept(EQUALS) ; atPos(in.offset) { constrExpr(vparamss) }
}
DefDef(mods, nme.CONSTRUCTOR, List(), vparamss, TypeTree(), rhs)
}
Expand Down
5 changes: 4 additions & 1 deletion test/files/neg/procedure-deprecation.check
Expand Up @@ -10,6 +10,9 @@ procedure-deprecation.scala:6: warning: procedure syntax is deprecated: instead,
procedure-deprecation.scala:7: warning: procedure syntax is deprecated: instead, add `: Unit =` to explicitly declare `boz`'s return type
def boz(i: Int, l: Long) {}
^
procedure-deprecation.scala:8: warning: procedure syntax is deprecated for constructors: add `=`, as in method definition
def this(i: Int) { this() } // Don't complain here! or maybe do complain
^
error: No warnings can be incurred under -Werror.
4 warnings
5 warnings
1 error
4 changes: 2 additions & 2 deletions test/files/neg/procedure-deprecation.scala
@@ -1,10 +1,10 @@
// scalac: -deprecation -Xfatal-warnings
// scalac: -Werror -Xlint:deprecation
//
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 this(i: Int) { this() } // Don't complain here! or maybe do complain
def foz: Unit // Don't complain here!
}
8 changes: 7 additions & 1 deletion test/files/neg/procedure-removal.check
Expand Up @@ -10,4 +10,10 @@ procedure-removal.scala:6: error: procedure syntax is unsupported: instead, add
procedure-removal.scala:7: error: procedure syntax is unsupported: instead, add `: Unit =` to explicitly declare `boz`'s return type
def boz(i: Int, l: Long) {}
^
4 errors
procedure-removal.scala:8: error: '=' expected but '{' found.
def this(i: Int) { this() } // Don't complain here! Just slap them with an error.
^
procedure-removal.scala:9: error: 'this' expected.
def foz: Unit // Don't complain here!
^
6 errors
2 changes: 1 addition & 1 deletion test/files/neg/procedure-removal.scala
Expand Up @@ -5,6 +5,6 @@ abstract class Foo {
def baz
def boo(i: Int, l: Long)
def boz(i: Int, l: Long) {}
def this(i: Int) { this() } // Don't complain here!
def this(i: Int) { this() } // Don't complain here! Just slap them with an error.
def foz: Unit // Don't complain here!
}

0 comments on commit 5d7314c

Please sign in to comment.