Skip to content

Commit d76d643

Browse files
committed
Fix patch for constructors with procedure syntax
A constructor def this() { ... } needs to be rewritten to def this() = { ... } not to def this(): Unit = { ... }
1 parent ba3f0a5 commit d76d643

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,17 +1762,18 @@ object Parsers {
17621762
* DefSig ::= id [DefTypeParamClause] ParamClauses
17631763
*/
17641764
def defDefOrDcl(mods: Modifiers): Tree = atPos(tokenRange) {
1765-
def scala2ProcedureSyntax =
1766-
testScala2Mode("Procedure syntax no longer supported; `: Unit =' should be inserted here") && {
1767-
patch(source, Position(in.lastOffset),
1768-
if (in.token == LBRACE) ": Unit =" else ": Unit ")
1765+
def scala2ProcedureSyntax(resultTypeStr: String) = {
1766+
val toInsert = if (in.token == LBRACE) s"$resultTypeStr =" else ": Unit "
1767+
testScala2Mode(s"Procedure syntax no longer supported; `$toInsert' should be inserted here") && {
1768+
patch(source, Position(in.lastOffset), toInsert)
17691769
true
17701770
}
1771+
}
17711772
if (in.token == THIS) {
17721773
in.nextToken()
17731774
val vparamss = paramClauses(nme.CONSTRUCTOR)
17741775
val rhs = {
1775-
if (!(in.token == LBRACE && scala2ProcedureSyntax)) accept(EQUALS)
1776+
if (!(in.token == LBRACE && scala2ProcedureSyntax(""))) accept(EQUALS)
17761777
atPos(in.offset) { constrExpr() }
17771778
}
17781779
makeConstructor(Nil, vparamss, rhs).withMods(mods)
@@ -1789,7 +1790,7 @@ object Parsers {
17891790
}
17901791
else if (!tpt.isEmpty)
17911792
EmptyTree
1792-
else if (scala2ProcedureSyntax) {
1793+
else if (scala2ProcedureSyntax(": Unit")) {
17931794
tpt = scalaUnit
17941795
if (in.token == LBRACE) expr()
17951796
else EmptyTree

0 commit comments

Comments
 (0)