Currently, the phase MoveStatic has two functionality:
@static members from the companion object A to the class AAIn an earlier phase, CheckStatic checks that @static members only locate in the companion object A. This restriction is just for semantic-correctness of user-written programs (to avoid changing the typer). For code that is synthesized from compiler phases, this restriction is annoying.
We can make @static a general mechanism in the compiler by splitting MoveStatic into two phases:
CheckStatic)StaticConstructors that synthesize the static constructor for static fields.The phase CompleteJavaEnums will benefit from the refactoring #8008.
I think we should just forbid user-code from using @static, it's a language feature which has not been properly specified and is currently really hard to use correctly (for example, if a lambda appears in a @static def, it will be translated to a non-static def, thus defeating the purpose of using @static)
Then we can change @static to be an internal annotation.
I would not be so rash throwing out @static. It solves real pain points of interop and getting the last drop of performance. It could need some attention to spec what it does and change the implementation to be more explicit when @static cannot be implemented correctly.
Most helpful comment
I think we should just forbid user-code from using
@static, it's a language feature which has not been properly specified and is currently really hard to use correctly (for example, if a lambda appears in a @static def, it will be translated to a non-static def, thus defeating the purpose of using @static)