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

Fix #22226: Use classOf[BoxedUnit] for Unit array in ArrayConstructors. #22238

Merged

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Dec 18, 2024

The ArrayConstructors phase rewrites array constructors to calls to scala.runtime.Arrays.newArray. When it does that, it must pass the run-time jl.Class of the element type. Previously, it used classOf[Unit] when creating an Array[Unit] (or nested). That is not correct, as from the Java perspective, we need to create Array[BoxedUnit].

We now identify elemType <: Unit and replace it with BoxedUnit.


This highlights a limitation of the Scala.js backend. We should rewrite calls to newArray in the backend to use direct array creation instead.

…structors`.

The `ArrayConstructors` phase rewrites array constructors to calls
to `scala.runtime.Arrays.newArray`. When it does that, it must pass
the run-time `jl.Class` of the element type. Previously, it used
`classOf[Unit]` when creating an `Array[Unit]` (or nested). That
is not correct, as from the Java perspective, we need to create
`Array[BoxedUnit]`.

We now identify `elemType <: Unit` and replace it with `BoxedUnit`.

---

This highlights a limitation of the Scala.js backend. We should
rewrite calls to `newArray` in the backend to use direct array
creation instead.
@hamzaremmal hamzaremmal merged commit bd1f004 into scala:main Dec 18, 2024
29 checks passed
@hamzaremmal hamzaremmal deleted the sjs-fix-array-of-unit-creation branch December 18, 2024 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants