Skip to content

Commit

Permalink
Fix patch for constructors with procedure syntax
Browse files Browse the repository at this point in the history
A constructor

     def this() { ... }

needs to be rewritten to

     def this() = { ... }

not to

     def this(): Unit = { ... }
  • Loading branch information
odersky committed Mar 9, 2016
1 parent ba3f0a5 commit d76d643
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1762,17 +1762,18 @@ object Parsers {
* DefSig ::= id [DefTypeParamClause] ParamClauses
*/
def defDefOrDcl(mods: Modifiers): Tree = atPos(tokenRange) {
def scala2ProcedureSyntax =
testScala2Mode("Procedure syntax no longer supported; `: Unit =' should be inserted here") && {
patch(source, Position(in.lastOffset),
if (in.token == LBRACE) ": Unit =" else ": Unit ")
def scala2ProcedureSyntax(resultTypeStr: String) = {
val toInsert = if (in.token == LBRACE) s"$resultTypeStr =" else ": Unit "
testScala2Mode(s"Procedure syntax no longer supported; `$toInsert' should be inserted here") && {
patch(source, Position(in.lastOffset), toInsert)
true
}
}
if (in.token == THIS) {
in.nextToken()
val vparamss = paramClauses(nme.CONSTRUCTOR)
val rhs = {
if (!(in.token == LBRACE && scala2ProcedureSyntax)) accept(EQUALS)
if (!(in.token == LBRACE && scala2ProcedureSyntax(""))) accept(EQUALS)
atPos(in.offset) { constrExpr() }
}
makeConstructor(Nil, vparamss, rhs).withMods(mods)
Expand All @@ -1789,7 +1790,7 @@ object Parsers {
}
else if (!tpt.isEmpty)
EmptyTree
else if (scala2ProcedureSyntax) {
else if (scala2ProcedureSyntax(": Unit")) {
tpt = scalaUnit
if (in.token == LBRACE) expr()
else EmptyTree
Expand Down

0 comments on commit d76d643

Please sign in to comment.