Skip to content

Commit 8936411

Browse files
committed
Make indentation significant in old-style control syntax
Indentation was significant only after new-style if-then, while-do, for-yield, for-do. This was prone to cause gotchas. We now treat indentation as significant also if the conditions or enumerators of these constructs use parens or braces.
1 parent f89bd19 commit 8936411

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,8 +1596,10 @@ object Parsers {
15961596
if (rewriteToOldSyntax()) revertToParens(t)
15971597
in.nextToken()
15981598
}
1599-
else if (rewriteToNewSyntax(t.span))
1600-
dropParensOrBraces(t.span.start, s"${tokenString(altToken)}")
1599+
else
1600+
in.observeIndented()
1601+
if (rewriteToNewSyntax(t.span))
1602+
dropParensOrBraces(t.span.start, s"${tokenString(altToken)}")
16011603
t
16021604
}
16031605
else {
@@ -2260,6 +2262,7 @@ object Parsers {
22602262
dropParensOrBraces(start, if (in.token == YIELD || in.token == DO) "" else "do")
22612263
}
22622264
}
2265+
in.observeIndented()
22632266
res
22642267
}
22652268
else {

tests/pos/indent4.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
object testindent
2+
3+
if (true)
4+
val x = 1
5+
println(x)
6+
7+
while (false)
8+
val x = 1
9+
println(x)
10+
11+
for (x <- List(1, 2, 3))
12+
val y = x
13+
println(y)
14+
15+
for { x <- List(1, 2, 3) }
16+
val y = x
17+
println(y)
18+
19+
for {
20+
x <- List(1, 2, 3)
21+
}
22+
val y = x
23+
println(y)
24+

0 commit comments

Comments
 (0)