Skip to content

Commit e6fbce1

Browse files
committed
Fix #8982: Insert colons when rewriting classes to indentation syntax
Allow `for {` under -new-syntax
1 parent b4338a8 commit e6fbce1

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,7 @@ object Parsers {
797797
canRewrite &= (in.isAfterLineEnd || statCtdTokens.contains(in.token)) // test (5)
798798
if (canRewrite && (!colonRequired || in.colonSyntax)) {
799799
val openingPatchStr =
800-
if (!colonRequired) ""
801-
else if (testChar(startOpening - 1, Chars.isOperatorPart(_))) " :"
800+
if (testChar(startOpening - 1, Chars.isOperatorPart(_))) " :"
802801
else ":"
803802
val (startClosing, endClosing) = closingElimRegion()
804803
patch(source, Span(startOpening, endOpening), openingPatchStr)
@@ -2469,11 +2468,10 @@ object Parsers {
24692468
val pos = t.sourcePos
24702469
pos.startLine < pos.endLine
24712470
}
2472-
if (rewriteToNewSyntax(Span(start)) && (leading == LBRACE || !hasMultiLineEnum)) {
2471+
if in.newSyntax && in.rewrite && (leading == LBRACE || !hasMultiLineEnum) then
24732472
// Don't rewrite if that could change meaning of newlines
24742473
newLinesOpt()
24752474
dropParensOrBraces(start, if (in.token == YIELD || in.token == DO) "" else "do")
2476-
}
24772475
}
24782476
in.observeIndented()
24792477
res

tests/pos/i8982.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
object Foo {
3+
def bar(x: Int): Unit = {
4+
println(x)
5+
}
6+
}
7+
8+
class Baz(n: Int) {
9+
def printRepeat(repeat: Int) = {
10+
for {
11+
x <- 1 to repeat
12+
} println(s"$x - ${n * x}")
13+
}
14+
}

0 commit comments

Comments
 (0)