You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
java.lang.IllegalArgumentException: requirement failed: a member can have a static constructor name iff it is in the static constructor namespace
Error: at scala.Predef$.require(Predef.scala:337)
Error: at org.scalajs.ir.Trees$MethodDef.<init>(Trees.scala:1148)
Error: at org.scalajs.ir.Trees$MethodDef$.apply(Trees.scala:1134)
Error: at dotty.tools.backend.sjs.JSCodeGen.genMethodDef(JSCodeGen.scala:1563)
Error: at dotty.tools.backend.sjs.JSCodeGen.genMethodWithCurrentLocalNameScope$$anonfun$1(JSCodeGen.scala:1529)
Error: at dotty.tools.backend.sjs.JSCodeGen.withPerMethodBodyState$$anonfun$1(JSCodeGen.scala:106)
Error: at dotty.tools.backend.sjs.ScopedVar$.withScopedVars(ScopedVar.scala:33)
Error: at dotty.tools.backend.sjs.JSCodeGen.withPerMethodBodyState(JSCodeGen.scala:107)
Error: at dotty.tools.backend.sjs.JSCodeGen.genMethodWithCurrentLocalNameScope(JSCodeGen.scala:1535)
...
Expectation
It should work with val just like it does with defs. The following compiles fine:
objectInvoker:@static defx=""// methods work fine@static deff():Unit= println(x)
The text was updated successfully, but these errors were encountered:
The fields themselves and accesses to them can now be compiled. But the class initializer, which must actually initialize these fields with their right-hand-side, is not triggered.
It's unclear how to deal with that. The Scala.js IR doesn't have a notion of a class initializer that is called upon first access to a static field. It has static initializers, but those are never dead-code-eliminated. They are classpath-wide forced startup code.
We would have to manually generate a call to a one-off initializer at the beginning of every static method, and at the beginning of every instance constructor.
We also don't have any public ABI defined for mutating static fields, so that would have to be defined as well.
Workaround: don't use @static in Scala.js.
I'm afraid it's a half-baked feature in dotc to begin with: never discussed/validated in public discussions nor in SIP meetings, and not documented. So I don't think I will prioritize this.
Compiler version
3.1.1
Minimized code
Output
Expectation
It should work with val just like it does with defs. The following compiles fine:
The text was updated successfully, but these errors were encountered: