Skip to content

Commit 22e9224

Browse files
authored
Merge pull request #13412 from som-snytt/issue/13410
Remove leading infix test for if condition
2 parents f819617 + 79c7ae9 commit 22e9224

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,14 +1830,14 @@ object Parsers {
18301830
* the initially parsed (...) region?
18311831
*/
18321832
def toBeContinued(altToken: Token): Boolean =
1833-
if in.isNewLine || migrateTo3 then
1834-
false // a newline token means the expression is finished
1835-
else if !in.canStartStatTokens.contains(in.token)
1836-
|| in.isLeadingInfixOperator(inConditional = true)
1837-
then
1838-
true
1839-
else
1840-
followedByToken(altToken) // scan ahead to see whether we find a `then` or `do`
1833+
inline def canContinue =
1834+
!in.canStartStatTokens.contains(in.token) // not statement, so take as continued expr
1835+
|| followedByToken(altToken) // scan ahead to see whether we find a `then` or `do`
1836+
1837+
!in.isNewLine // a newline token means the expression is finished
1838+
&& !migrateTo3 // old syntax
1839+
&& canContinue
1840+
end toBeContinued
18411841

18421842
def condExpr(altToken: Token): Tree =
18431843
val t: Tree =

tests/pos/indent.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ object Test:
8282
x < 10
8383
do ()
8484

85+
def sign(x: Int): Int =
86+
if (x > 0) 1
87+
else if (x < 0) - 1 // was: value - is not a member of Boolean
88+
else 0
89+
def lessPersuasively(x: Int): Unit =
90+
while (x < 0) - 42 // was: value - is not a member of Boolean
91+
end Test
92+
8593
class Test2:
8694
self =>
8795
def foo(x: Int) =
@@ -147,4 +155,4 @@ class Coder(words: List[String]):
147155
end Coder
148156

149157
object Test22:
150-
def foo: Int = 22
158+
def foo: Int = 22

0 commit comments

Comments
 (0)