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

Final val of Java enum is not a constant value #21881

Open
som-snytt opened this issue Nov 4, 2024 · 0 comments
Open

Final val of Java enum is not a constant value #21881

som-snytt opened this issue Nov 4, 2024 · 0 comments

Comments

@som-snytt
Copy link
Contributor

Compiler version

3.5.2

Minimized code

class C:

  final val Seconds = java.util.concurrent.TimeUnit.SECONDS
  //inline val SecondSeconds = java.util.concurrent.TimeUnit.SECONDS // not a literal

  @OutputTimeUnit(Seconds)
  def f(): Unit = ()

  @OutputTimeUnit(java.util.concurrent.TimeUnit.SECONDS)
  def ok(): Unit = ()

where

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.concurrent.TimeUnit;

@Inherited
@Target({ElementType.METHOD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface OutputTimeUnit {

    /**
     * @return Time unit to use.
     */
    TimeUnit value();

}

Output

7 |  @OutputTimeUnit(Seconds)
  |                  ^^^^^^^
  |                  Annotation argument is not a constant

Expectation

Works as in Scala 2.

Spec says platform enum is a constant value expression; Seconds is a constant value definition.

@som-snytt som-snytt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 4, 2024
@Gedochao Gedochao added compat:java regression:scala2 and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 4, 2024
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

2 participants