Skip to content

scalac unable to parse java annotations in a file in the empty package with no imports #4071

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

Closed
scabug opened this issue Dec 11, 2010 · 4 comments
Milestone

Comments

@scabug
Copy link

scabug commented Dec 11, 2010

One wonders what our test suite is doing exactly given that this java file is verbatim from a currently active test.

% scalac29 test/files/jvm/t3003/Annot.java 
test/files/jvm/t3003/Annot.java:2: error: `package' expected but `public' found.
public @interface Annot {
^
test/files/jvm/t3003/Annot.java:4: error: identifier expected but eof found.
}
 ^
two errors found

Here is the file.

@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
public @interface Annot {
    Class<?> optionType();
}

It is successfully parsed if written like this:

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
public @interface Annot {
    Class<?> optionType();
}
@scabug
Copy link
Author

scabug commented Dec 11, 2010

Imported From: https://issues.scala-lang.org/browse/SI-4071?orig=1
Reporter: @paulp

@scabug
Copy link
Author

scabug commented Jul 10, 2012

@retronym said:
This will do it:

@X
public @interface Annot {
}

@interface X {}

@scabug scabug added the quickfix label Apr 7, 2017
@scabug scabug added this to the Backlog milestone Apr 7, 2017
anne-decusatis added a commit to anne-decusatis/ratatool that referenced this issue Aug 21, 2019
Sometimes these are generated without a namespace
Then, we fail to compile because of this Scala bug: scala/bug#4071
We can make sure it gets generated with a namespace by specifying namespace
this is valid avro per https://avro.apache.org/docs/current/spec.html#Enums
anne-decusatis added a commit to spotify/ratatool that referenced this issue Aug 21, 2019
Sometimes these are generated without a namespace
Then, we fail to compile because of this Scala bug: scala/bug#4071
We can make sure it gets generated with a namespace by specifying namespace
this is valid avro per https://avro.apache.org/docs/current/spec.html#Enums
anne-decusatis added a commit to spotify/ratatool that referenced this issue Aug 23, 2019
* First pass at CircleCI config.yml 

based on bits of Scio's config.yml

* Remove the invalid(?) yaml & and *

* Define jobs outside of build workflow

* Fix line breaks in sbt command definition

* Remove Travis build

* Add namespace to TestRecord enum & fixed (#166)

Sometimes these are generated without a namespace
Then, we fail to compile because of this Scala bug: scala/bug#4071
We can make sure it gets generated with a namespace by specifying namespace
this is valid avro per https://avro.apache.org/docs/current/spec.html#Enums
@SethTisue SethTisue modified the milestones: Backlog, 2.13.14 Mar 21, 2025
@SethTisue
Copy link
Member

SethTisue commented Mar 21, 2025

Scala 3 still has the issue, though (as of 3.7.0-RC1). if that's a concern to anyone, please open a ticket in the Scala 3 tracker

@som-snytt
Copy link

This was
scala/scala#10734

Dotty
scala/scala3#20063

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants