Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

clarify leading infix example #19763

Unanswered
kitbellew asked this question in General Question
Discussion options

started here: 4cc6c06#r138896963

the question is: in this example

foo
???
??? match { case _ => 0 }

why isn't the first instance of ??? considered to be a leading infix operator? it seems to satisfy all conditions mentioned in the documentation:

  • symbolic
  • starts new line
  • not preceded by blank line
  • next token is after whitespace
  • next token is after minimum indent
  • next token can start an expression
You must be logged in to vote

Replies: 3 comments

Comment options

I think we want to exclude operator symbols (except prefix operators) from the tokens that can start an expression. The spec should make that clear.

You must be logged in to vote
0 replies
Comment options

Looking at the code in Scanner confirms this:

 def assumeStartsExpr(lexeme: TokenData) =
 (canStartExprTokens.contains(lexeme.token) || lexeme.token == COLONeol)
 && (!lexeme.isOperator || nme.raw.isUnary(lexeme.name))
You must be logged in to vote
0 replies
Comment options

The backticked identifier is a non-unary operator, so this is rejected:

 val a = 7
 val x = 1
 +
 `a`
 *
 6
 assert(x == 1 + 7 * 6, x) // was: 1, now: successor(42)

https://github.com/scala/scala/blob/2.13.x/test/files/run/multiLineOps.scala

If accepted, the OP would be foo.???(???) match { }. The following is "huh" not "hibi".

 val y =
 "hi"
 +
 "bye" match { case "bye" => "bi" case _ => "huh" }

Scala 2 tries to closely approximate Scala 3 modulo indentation, but for some reason diverged on this point:

 1
 +
 `a` * 6

is OK but not

 1
 +
 `a` *= 6

where it is trying to determine whether the backticked ident is an operator. Some ancient messaging that is not leading infix aware suggests adding a semicolon.

mlo.scala:10: error: value *= is not a member of Int
possible cause: maybe a semicolon is missing before `value *=`?
 Expression does not convert to assignment because receiver is not assignable.
 `a` *= 6
 ^

It disdains to suggest != etc as seen in Scala 3.

value *= is not a member of Int - did you mean Int.!=? or perhaps Int.<=?

I just spent too many minutes reading my code comment from 2021. For me, that was mid-pandemic and early funemployment, so it was a lot of brain fog ago.

scala/bug#12970

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /