Issue with compiling `@main` annotation when there is extra lines
See original GitHub issueJust to make sure it’s tracked here, I figured I’d create this and link it to the issue in Metals.
So I’ve been playing around with this a bit to see if I can consistently reproduce it, and I can. It’s very odd because it’s a certain combination of things based on empty lines. For example, if you create a new project with the Dotty g8 template and change the main method to be as follows at the top level:
Just one blank line, no package declaration. Bloop has no issue with this.
@main def main(): Unit = {
println("Hello world!")
println(msg)
}
def msg = "I was compiled by dotty :)"
Add one more empty line on top and you’ll get the following error:
This…
@main def main(): Unit = {
println("Hello world!")
println(msg)
}
def msg = "I was compiled by dotty :)"
Produces this:
❯ bloop run root
Compiling root (1 Scala source)
[E] [E1] src/main/scala/Main.scala:2:1
[E] Found: main
[E] Required: scala.annotation.Annotation
[E] L2: @main def main(): Unit = {
[E] ^
[E] src/main/scala/Main.scala: L2 [E1]
Compiled root (224ms)
[E] Failed to compile 'root'
Add in a package declaration and make sure there is only one line between package declaration and main method, no issue.
package example
@main def main(): Unit = {
println("Hello world!")
println(msg)
}
def msg = "I was compiled by dotty :)"
If you add in another blank line, you’ll get the issue. The same thing happens if you add a blank line in at the top of the method.
package example
@main def main(): Unit = {
println("Hello world!")
println(msg)
}
def msg = "I was compiled by dotty :)"
All of the cases produce the same error from bloop. Note that all of these can be compile and ran with sbt with no issue.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
ok, I’ll try to reproduce it with the current bloop and then with your version. Will it be safe to close this and related issues if there aren’t any problems with compilation?
I’ll go ahead and close then. I haven’t looked back at this in a long time or noticed it so closing.