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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class ArrayConstructors extends MiniPhase {

override def transformApply(tree: tpd.Apply)(using Context): tpd.Tree = {
def expand(elemType: Type, dims: List[Tree]) =
tpd.newArray(elemType, tree.tpe, tree.span, JavaSeqLiteral(dims, TypeTree(defn.IntClass.typeRef)))
val elemTypeNonVoid =
if elemType.isValueSubType(defn.UnitType) then defn.BoxedUnitClass.typeRef
else elemType
tpd.newArray(elemTypeNonVoid, tree.tpe, tree.span, JavaSeqLiteral(dims, TypeTree(defn.IntClass.typeRef)))

if (tree.fun.symbol eq defn.ArrayConstructor) {
val TypeApply(tycon, targ :: Nil) = tree.fun: @unchecked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ class RegressionTestScala3 {
assertEquals(5, Issue14289.Container.b())
assertEquals(true, Issue14289.Container.c())
}

@Test def createArrayOfUnitIssue22226(): Unit = {
val a = Array.ofDim[Unit](0)
assertSame(classOf[Array[Unit]], a.getClass())

val b = new Array[Unit](0)
assertSame(classOf[Array[Unit]], b.getClass())

val c = Array.ofDim[Unit](0, 0)
assertSame(classOf[Array[Array[Unit]]], c.getClass())
}
}

object RegressionTestScala3 {
Expand Down
Loading