Skip to content

Recognize leading infix operator in front of : at eol #12219

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
Apr 26, 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
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ object Scanners {
&& {
// Is current lexeme assumed to start an expression?
// This is the case if the lexime is one of the tokens that
// starts an expression. Furthermore, if the previous token is
// in backticks, the lexeme may not be a binary operator.
// starts an expression or it is a COLONEOL. Furthermore, if
// the previous token is in backticks, the lexeme may not be a binary operator.
// I.e. in
//
// a
Expand All @@ -388,7 +388,7 @@ object Scanners {
// in backticks and is a binary operator. Hence, `x` is not classified as a
// leading infix operator.
def assumeStartsExpr(lexeme: TokenData) =
canStartExprTokens.contains(lexeme.token)
(canStartExprTokens.contains(lexeme.token) || lexeme.token == COLONEOL)
&& (!lexeme.isOperator || nme.raw.isUnary(lexeme.name))
val lookahead = LookaheadScanner()
lookahead.allowLeadingInfixOperators = false
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/i12218.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import language.experimental.fewerBraces
@main def runTest(): Unit =
val arr = Array(1,2,3)
if
arr.isEmpty
|| :
val first = arr(0)
first != 1
then println("invalid arr")
else println("valid arr")