-
Notifications
You must be signed in to change notification settings - Fork 1.1k
clarify leading infix example #19763
-
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
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
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))
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.