-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Report a clearer error message for unexpected final
modifier
#17579
Comments
Scala 2: $ scala-cli repl -S 2.13
Welcome to Scala 2.13.14 (OpenJDK 64-Bit Server VM, Java 17.0.8).
Type in expressions for evaluation. Or try :help.
scala> final val x = 42
val x: Int(42) = 42
scala> val x = 42
val x: Int = 42 Scala 3: $ scala-cli repl -S 3.4
Welcome to Scala 3.4.2 (17.0.8, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> final val x = 42
-- [E088] Syntax Error: --------------------------------------------------------
1 |final val x = 42
| ^^^
| Expected start of definition
|
| longer explanation available when compiling with `-explain`
scala> final def x = 42
-- [E088] Syntax Error: --------------------------------------------------------
1 |final def x = 42
| ^^^
| Expected start of definition
|
| longer explanation available when compiling with `-explain` Why should this work; shouldn't What is the use-case for this? |
Note: you get the same error when trying to define a ➜ ~/scala-snippets-5 cat finalVal.scala
package finalVal
@main def Main =
final val x = 42
()
➜ ~/scala-snippets-5 scala-cli run finalVal.scala
Compiling project (Scala 3.4.1, JVM (17))
[error] ./finalVal.scala:4:9
[error] Expected start of definition
[error] final val x = 42
[error] ^^^
Error compiling project (Scala 3.4.1, JVM (17))
Compilation failed |
|
This issue has been re-purposed to making the error message clearer. Note that this will not be specific to the REPL. |
final
modifier
This issue was picked for the Scala Issue Spree of today, June 11th. @aherlihy, @mbovel, @bracevac, @EugeneFlesselle will be working on it. |
Scratch that, I wasn't compiling it correctly (getting other compile errors on what I was working on). |
Ah, indeed: ➜ ~/scala-snippets-5 scala-cli run -O -explain finalVal.scala
Compiling project (Scala 3.4.1, JVM (17))
[error] ./finalVal.scala:4:9
[error] Expected start of definition
[error]
[error] Explanation
[error] ===========
[error] You have to provide either class, trait, object, or enum definitions after qualifiers
[error] final val x = 42
[error] ^^^
Error compiling project (Scala 3.4.1, JVM (17))
Compilation failed However, this message also doesn't seem particularly helpful. |
Expectation
That seems like a natural thing to do in the REPL.
The text was updated successfully, but these errors were encountered: