8000 Fix missing `CheckNotNull`s in the deserialization hacks of `newInsta… · scala-js/scala-js@0b94e03 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b94e03

Browse files
committed
Fix missing CheckNotNulls in the deserialization hacks of newInstance.
1 parent f0c74cb commit 0b94e03

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

ir/shared/src/main/scala/org/scalajs/ir/Serializers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,10 +1638,10 @@ object Serializers {
16381638
}
16391639

16401640
def arrayLength(t: Tree)(implicit pos: Position): Tree =
1641-
UnaryOp(UnaryOp.Array_length, t)
1641+
UnaryOp(UnaryOp.Array_length, UnaryOp(UnaryOp.CheckNotNull, t))
16421642

16431643
def getClass(t: Tree)(implicit pos: Position): Tree =
1644-
UnaryOp(UnaryOp.GetClass, t)
1644+
UnaryOp(UnaryOp.GetClass, UnaryOp(UnaryOp.CheckNotNull, t))
16451645

16461646
val jlClassRef = ClassRef(ClassClass)
16471647
val intArrayTypeRef = ArrayTypeRef(IntRef, 1)

linker/shared/src/test/scala/org/scalajs/linker/BackwardsCompatTest.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,33 @@ class BackwardsCompatTest {
109109
test(classDefs, MainTestModuleInitializers)
110110
}
111111

112+
@Test
113+
def testArrayNewInstanceHacks_Issue5107(): AsyncResult = await {
114+
val ReflectArrayClass = ClassName("java.lang.reflect.Array")
115+
116+
val ClassClassRef = ClassRef(ClassClass)
117+
118+
val AI = ArrayTypeRef(IntRef, 1)
119+
120+
/* jlr.Array.newInstance(classOf[String], 5)
121+
* jlr.Array.newInstance(classOf[String], Array(5, 4))
122+
*/
123+
val classDefs = Seq(
124+
mainTestClassDef(Block(
125+
systemOutPrintln(
126+
ApplyStatic(EAF, ReflectArrayClass, m("newInstance", List(ClassClassRef, I), O),
127+
List(ClassOf(T), int(5)))(AnyType)
128+
),
129+
systemOutPrintln(
130+
ApplyStatic(EAF, ReflectArrayClass, m("newInstance", List(ClassClassRef, AI), O),
131+
List(ClassOf(T), ArrayValue(AI, List(int(5), int(4)))))(AnyType)
132+
)
133+
))
134+
)
135+
136+
test(classDefs, MainTestModuleInitializers)
137+
}
138+
112139
private def test(classDefs: Seq[ClassDef],
113140
moduleInitializers: Seq[ModuleInitializer]): Future[_] = {
114141
val classDefFiles = classDefs.map(MemClassDefIRFile(_))

0 commit comments

Comments
 (0)
0