question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with compiling `@main` annotation when there is extra lines

See original GitHub issue

Just 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kpodsiadcommented, Feb 15, 2022

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?

0reactions
ckipp01commented, Feb 15, 2022

I’ll go ahead and close then. I haven’t looked back at this in a long time or noticed it so closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Annotations are only available if source level is 5.0 syntax ...
I am compiling the code from command line. How can I resolve the problem. Here is some information that may be useful: $java...
Read more >
Lesson: Common Problems (and Their Solutions) (The Java ...
This beginner Java tutorial describes getting started with Java and setting up your Netbeans IDE.
Read more >
Annotations in Java - GeeksforGeeks
Annotations help to associate metadata (information) to the program elements i.e. instance variables, constructors, methods, classes, etc.
Read more >
Main Methods in Scala 3 - Scala Documentation
Scala 3 offers a new way to define programs that can be invoked from the command line: Adding a @main annotation to a...
Read more >
Improve code inspection with annotations - Android Developers
Annotations allow you to provide hints to code inspections tools like Lint, to help detect these more subtle code problems. They are added...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found