From 46a7f612341e29de2932a9a17cedf76704a2c9eb Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Mon, 8 Apr 2024 11:52:52 +0200 Subject: [PATCH] Fix #310 --- resources/bytecode/javFiles/Bug310.jav | 9 +++++++++ src/main/java/de/dhbwstuttgart/bytecode/Codegen.java | 4 +++- src/test/java/TestComplete.java | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 resources/bytecode/javFiles/Bug310.jav diff --git a/resources/bytecode/javFiles/Bug310.jav b/resources/bytecode/javFiles/Bug310.jav new file mode 100644 index 00000000..05393385 --- /dev/null +++ b/resources/bytecode/javFiles/Bug310.jav @@ -0,0 +1,9 @@ +import java.lang.Integer; +import java.lang.String; + +public class Bug310 { + Integer i = 3; + public toString() { + return i.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java index dda6aadd..601316f6 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java @@ -1029,8 +1029,10 @@ public class Codegen { break; } case TargetMethodCall call: { - if (!call.isStatic()) + if (!call.isStatic()) { generate(state, call.expr()); + boxPrimitive(state, call.expr().type()); + } for (var i = 0; i < call.args().size(); i++) { var e = call.args().get(i); var arg = call.parameterTypes().get(i); diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index f3455c9b..f06f1a19 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -1031,4 +1031,12 @@ public class TestComplete { var instance = clazz.getDeclaredConstructor().newInstance(); clazz.getDeclaredMethod("main").invoke(instance); } + + @Test + public void testBug310() throws Exception { + var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug310.jav"); + var clazz = classFiles.get("Bug310"); + var instance = clazz.getDeclaredConstructor().newInstance(); + assertEquals(clazz.getDeclaredMethod("toString").invoke(instance), "3"); + } }