Skip to content

Commit 3a8d2a6

Browse files
authored
Merge pull request #12219 from dotty-staging/fix-12218
Recognize leading infix operator in front of `:` at eol
2 parents 831b062 + 89344b3 commit 3a8d2a6

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ object Scanners {
377377
&& {
378378
// Is current lexeme assumed to start an expression?
379379
// This is the case if the lexime is one of the tokens that
380-
// starts an expression. Furthermore, if the previous token is
381-
// in backticks, the lexeme may not be a binary operator.
380+
// starts an expression or it is a COLONEOL. Furthermore, if
381+
// the previous token is in backticks, the lexeme may not be a binary operator.
382382
// I.e. in
383383
//
384384
// a
@@ -388,7 +388,7 @@ object Scanners {
388388
// in backticks and is a binary operator. Hence, `x` is not classified as a
389389
// leading infix operator.
390390
def assumeStartsExpr(lexeme: TokenData) =
391-
canStartExprTokens.contains(lexeme.token)
391+
(canStartExprTokens.contains(lexeme.token) || lexeme.token == COLONEOL)
392392
&& (!lexeme.isOperator || nme.raw.isUnary(lexeme.name))
393393
val lookahead = LookaheadScanner()
394394
lookahead.allowLeadingInfixOperators = false

tests/pos/i12218.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import language.experimental.fewerBraces
2+
@main def runTest(): Unit =
3+
val arr = Array(1,2,3)
4+
if
5+
arr.isEmpty
6+
|| :
7+
val first = arr(0)
8+
first != 1
9+
then println("invalid arr")
10+
else println("valid arr")

0 commit comments

Comments
 (0)