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

@static vals on Scala.js are not initialized #19441

Closed
armanbilge opened this issue Jan 13, 2024 · 4 comments
Closed

@static vals on Scala.js are not initialized #19441

armanbilge opened this issue Jan 13, 2024 · 4 comments

Comments

@armanbilge
Copy link
Contributor

Compiler version

3.4.0-RC1-bin-20240112-c50f2ff-NIGHTLY

Minimized code

//> using scala 3.4.0-RC1-bin-20240112-c50f2ff-NIGHTLY
//> using platform js

import scala.annotation.static
class Foo
object Foo {
  @static val bar: String = "bar"

  @main def main() = println(bar)
}

Output

undefined

Expectation

bar
@sjrd
Copy link
Member

sjrd commented Jan 13, 2024

@static never made it into the language spec. It's a dotc "compiler feature" for the JVM, not a language feature. Use at your own risk.

That said, PR welcome to make it work on Scala.js anyway. Expect hard problems near initialization semantics, indeed.

@sjrd sjrd added itype:enhancement help wanted exp:advanced area:scala.js and removed itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 13, 2024
@armanbilge
Copy link
Contributor Author

armanbilge commented Jan 13, 2024

It's a dotc "compiler feature" for the JVM, not a language feature.

Could an SJS-specific miniphase (or something) just drop the annotation? Edit: I'm not trying to use it on JS, I just want my code to cross-compile 😅

@sjrd
Copy link
Member

sjrd commented Jan 13, 2024

Maybe, if it doesn't affect observable semantics?

@dwijnand
Copy link
Member

Duplicate of #14710

@dwijnand dwijnand marked this as a duplicate of #14710 Jan 15, 2024
@dwijnand dwijnand closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 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

3 participants