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

Can't instantiate Array[Unit] with Scalajs #19876

Closed
Katrix opened this issue Mar 4, 2024 · 1 comment
Closed

Can't instantiate Array[Unit] with Scalajs #19876

Katrix opened this issue Mar 4, 2024 · 1 comment

Comments

@Katrix
Copy link
Contributor

Katrix commented Mar 4, 2024

Compiler version

3.4.0 and 3.3.3

Minimized code

new Array[Unit](1)

Original code that showed the bug

val arr = new Array[Unit](7)
var i: Int = 0
while (i < 7) {
  arr(i) = ()
  i += 1
}

arr

Output

[info]   org.scalajs.linker.runtime.UndefinedBehaviorError: java.lang.ClassCastException: [V cannot be cast to Ljava.lang.Void;
[info]   at $throwClassCastException(D:\DevProjects\Stable\perspective\dotty\derivation\.js\target\scala-3.3.3\perspective-derivation-test-fastopt\main.js:52:9)
[info]   at $throwArrayCastException(D:\DevProjects\Stable\perspective\dotty\derivation\.js\target\scala-3.3.3\perspective-derivation-test-fastopt\main.js:58:3)
[info]   at $asArrayOf_jl_Void(D:\DevProjects\Stable\perspective\dotty\derivation\.js\target\scala-3.3.3\perspective-derivation-test-fastopt\main.js:2774:70)
[info]   at ScalaJSError.testFun$proxy1$1(D:\DevProjects\Stable\perspective\dotty\derivation\.js\target\scala-3.3.3\perspective-derivation-test-fastopt\main.js:105391:13)
[info]   at {anonymous}()(D:\DevProjects\Stable\perspective\dotty\derivation\.js\target\scala-3.3.3\perspective-derivation-test-fastopt\main.js:105409:50)
[info]   at scala.scalajs.runtime.AnonFunction0.apply(D:\DevProjects\Stable\perspective\dotty\derivation\.js\target\scala-3.3.3\perspective-derivation-test-fastopt\main.js:55040:43)
[info]   at org.scalatest.Transformer.apply(D:\DevProjects\Stable\perspective\dotty\derivation\.js\target\scala-3.3.3\perspective-derivation-test-fastopt\main.js:73077:63)
[info]   at org.scalatest.Transformer.apply(D:\DevProjects\Stable\perspective\dotty\derivation\.js\target\scala-3.3.3\perspective-derivation-test-fastopt\main.js:73099:15)
[info]   at org.scalatest.funsuite.AnyFunSuiteLike$$anon$1.apply(D:\DevProjects\Stable\perspective\dotty\derivation\.js\target\scala-3.3.3\perspective-derivation-test-fastopt\main.js:62507:166)
[info]   at org.scalatest.funsuite.AnyFunSuiteLike.invokeWithFixture$1(D:\DevProjects\Stable\perspective\dotty\derivation\.js\target\scala-3.3.3\perspective-derivation-test-fastopt\main.js:103960:15)

Expectation

It runs and creates the array

@Katrix Katrix added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 4, 2024
@sjrd sjrd self-assigned this Mar 4, 2024
@sjrd sjrd added area:scala.js and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 4, 2024
@sjrd
Copy link
Member

sjrd commented Feb 16, 2025

Fixed by #22238

@sjrd sjrd closed this as completed Feb 16, 2025
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