Closed
Description
Compiler version
I can reproduce it on: 3.0.0-M3-bin-20201213-e8d748e-NIGHTLY
and 3.0.0-RC1-bin-20210122-6947b0f-NIGHTLY
Minimized code
object HelloWorld {
def whileLoop: Int = {
var i = 0
var acc = 0
while (i < 3) {
var `i'` = 0
while (`i'` < 4) {
acc += (i * `i'`)
`i'` += 1
}
i += 1
}
acc
}
def main(args: Array[String]): Unit = {
println(s"hello world: ${whileLoop}")
}
}
Output
-- Error: tests/pos/HelloWorld.scala:9:16 --------------------------------------
9 | `i'` += 1
| ^
| end of statement expected but integer literal found
-- [E040] Syntax Error: tests/pos/HelloWorld.scala:10:6 ------------------------
10 | }
| ^
| ';' expected, but '}' found
-- [E008] Not Found Error: tests/pos/HelloWorld.scala:8:12 ---------------------
8 | acc += (i * `i'`)
| ^^^^^^
| value += is not a member of Int - did you mean Int.!=?
-- [E008] Not Found Error: tests/pos/HelloWorld.scala:9:8 ----------------------
8 | acc += (i * `i'`)
9 | `i'` += 1
| ^
| value i' is not a member of Int.
| Note that `i'` is treated as an infix operator in Scala 3.
| If you do not want that, insert a `;` or empty line in front
| or drop any spaces behind the operator.
-- [E006] Not Found Error: tests/pos/HelloWorld.scala:9:13 ---------------------
9 | `i'` += 1
| ^^
| Not found: +=
longer explanation available when compiling with `-explain`
5 errors found
Expectation
Should compile and print hello world: 18
Workaround
Replace lines like:
`i'` += 1
to
`i'` = `i'` + 1