From 79c7ae9cb9c0e2261903583d2d53119c52f5bd7f Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sat, 28 Aug 2021 22:37:46 -0700 Subject: [PATCH] Remove leading infix test for if condition --- .../src/dotty/tools/dotc/parsing/Parsers.scala | 16 ++++++++-------- tests/pos/indent.scala | 10 +++++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index effbfe22f0e4..a61e4a2c6372 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1830,14 +1830,14 @@ object Parsers { * the initially parsed (...) region? */ def toBeContinued(altToken: Token): Boolean = - if in.isNewLine || migrateTo3 then - false // a newline token means the expression is finished - else if !in.canStartStatTokens.contains(in.token) - || in.isLeadingInfixOperator(inConditional = true) - then - true - else - followedByToken(altToken) // scan ahead to see whether we find a `then` or `do` + inline def canContinue = + !in.canStartStatTokens.contains(in.token) // not statement, so take as continued expr + || followedByToken(altToken) // scan ahead to see whether we find a `then` or `do` + + !in.isNewLine // a newline token means the expression is finished + && !migrateTo3 // old syntax + && canContinue + end toBeContinued def condExpr(altToken: Token): Tree = val t: Tree = diff --git a/tests/pos/indent.scala b/tests/pos/indent.scala index 03502a26fe79..6e027e1db085 100644 --- a/tests/pos/indent.scala +++ b/tests/pos/indent.scala @@ -82,6 +82,14 @@ object Test: x < 10 do () + def sign(x: Int): Int = + if (x > 0) 1 + else if (x < 0) - 1 // was: value - is not a member of Boolean + else 0 + def lessPersuasively(x: Int): Unit = + while (x < 0) - 42 // was: value - is not a member of Boolean +end Test + class Test2: self => def foo(x: Int) = @@ -147,4 +155,4 @@ class Coder(words: List[String]): end Coder object Test22: - def foo: Int = 22 \ No newline at end of file + def foo: Int = 22