Skip to content

Commit e444f9f

Browse files
committed
Void class literal fix (hotfix-6)
1 parent 383ccef commit e444f9f

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/main/kotlin/com/github/jonathanxd/codeapi/bytecode/util/LiteralUtil.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828
package com.github.jonathanxd.codeapi.bytecode.util
2929

30+
import com.github.jonathanxd.codeapi.CodeAPI
3031
import com.github.jonathanxd.codeapi.Types
3132
import com.github.jonathanxd.codeapi.literal.Literal
3233
import com.github.jonathanxd.codeapi.literal.Literals
@@ -89,7 +90,9 @@ object LiteralUtil {
8990
val type = num.value as CodeType
9091

9192
if(type.isPrimitive) {
92-
val wrapperTypeSpec = CodeTypeUtil.codeTypeToBinaryName(type.wrapperType ?: throw IllegalArgumentException("Primitive type '$type' has no wrapper version."))
93+
val wrapperType = if(type.`is`(Types.VOID)) CodeAPI.getJavaType(Void::class.java) else type.wrapperType ?: throw IllegalArgumentException("Primitive type '$type' has no wrapper version.")
94+
95+
val wrapperTypeSpec = CodeTypeUtil.codeTypeToBinaryName(wrapperType)
9396
val classType = CodeTypeUtil.toTypeDesc(Types.CLASS)
9497

9598
mv.visitFieldInsn(Opcodes.GETSTATIC, wrapperTypeSpec, "TYPE", classType)

src/test/java/com/github/jonathanxd/codeapi/test/asm/LiteralBugTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void literalBugTest() throws Throwable {
5454
CodeSource source = sourceOfParts(
5555
method(EnumSet.of(PUBLIC), "test", VOID, new CodeParameter[]{},
5656
sourceOfParts(
57-
Predefined.invokePrintln(Literals.CLASS(Integer.class))
57+
Predefined.invokePrintln(Literals.CLASS(Void.TYPE))
5858
)
5959
)
6060
);

src/test/resources/disassembled/LiteralBugTest_MyClass_Result.class.disassembled

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
md5: f08e583d0e08e79c9171c65bfb8eec6d
1+
md5: 870d9cb47d22c02f0028537876b6a126
22

33
version: Java 8 (52)
44
access: ACC_PUBLIC (33)
@@ -13,7 +13,7 @@ public class com.MyClass extends java.lang.Object {
1313
maxStack: 2, maxLocals: 1
1414
Label_0:
1515
getstatic java.lang.System.out (type: java.io.PrintStream)
16-
ldc Ljava/lang/Integer; // type: java.lang.Class
16+
getstatic java.lang.Void.TYPE (type: java.lang.Class)
1717
invokevirtual java.io.PrintStream.println(java.lang.Object)void (ownerIsInterface: false)
1818
return
1919
Label_1:

0 commit comments

Comments
 (0)