Skip to content
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

Java parser: java 'static final' field cannot be used as constant expression (i.e. in java annotation argument) #5791

Closed
scabug opened this issue May 12, 2012 · 3 comments

Comments

@scabug
Copy link

scabug commented May 12, 2012

Given two java classes:

public @interface Ann {
  int value();
}
public class Cls {
  public static final int KONST = 10;
}

and a Scala class

class T {
  @Ann(Cls.KONST)
  def foo { }
}

Compiling the three files together with scalac yields an error message:

lucmac:const luc$ ~/Downloads/latest/bin/scalac Ann.java Cls.java T.scala 
T.scala:2: error: annotation argument needs to be a constant; found: Cls.KONST
  @Ann(Cls.KONST)
           ^
one error found

Compiling first the java files and and putting their classfiles on the classpath allows compiling T.scala:

lucmac:const luc$ javac Ann.java Cls.java 
lucmac:const luc$ ~/Downloads/latest/bin/scalac -cp . T.scala 
lucmac:const luc$ 
@scabug
Copy link
Author

scabug commented May 12, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5791?orig=1
Reporter: @lrytz
See #5699, #2764
Duplicates #5333

@scabug
Copy link
Author

scabug commented May 12, 2012

@lrytz said:
2764 shows a similar problem with java enums

@scabug
Copy link
Author

scabug commented May 12, 2012

@soc said (edited on May 12, 2012 6:50:44 PM UTC):
Closely related to #5333 and #5699.

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

1 participant