Skip to content

Remove leading infix test for if condition #13412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
10 changes: 9 additions & 1 deletion tests/pos/indent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -147,4 +155,4 @@ class Coder(words: List[String]):
end Coder

object Test22:
def foo: Int = 22
def foo: Int = 22