-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Actually, the expectation that subsequent package statements continue to nest (until EOF) would be a cool feature (and arguably more consistent).
Discussed in #17874
Originally posted by alvinj February 28, 2021
When I incorrectly write code like this:
package test6
package t1
trait T1
package t2
trait T2
the compiler shows this error message:
-- [E040] Syntax Error: Test3.scala:7:0 ----------------------------------------
7 |trait T2
|^^^^^
|'{' expected, but 'end of statement' found
-- [E040] Syntax Error: Test3.scala:8:0 ----------------------------------------
8 |
|^
|'}' expected, but eof found
2 errors found
As I initially pointed out on Gitter, and Bjorn Regnell clarifies here, the error message could be more helpful, especially when using the significant indentation syntax. Bjorn’s suggests this:
'{' or ':' expected, but 'end of statement' found
I think it would be even more clear to state that the package statement needs to end with a : and possibly that the trait line needs to be indented, but I don’t know what information is available. I’ve seen some other Scala 3 error messages that are really terrific and helpful — varargs, match expressions, trait inheritance, etc. — which is why I mention all of this.