diff --git a/src/main/java/de/dhbwstuttgart/target/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/target/bytecode/Codegen.java index e1744b4d..bd6e0925 100755 --- a/src/main/java/de/dhbwstuttgart/target/bytecode/Codegen.java +++ b/src/main/java/de/dhbwstuttgart/target/bytecode/Codegen.java @@ -873,6 +873,7 @@ public class Codegen { mv.visitLabel(start); if (_for.termination() != null) generate(state, _for.termination()); + else mv.visitInsn(ICONST_1); mv.visitJumpInsn(IFEQ, end); generate(state, _for.body()); if (_for.increment() != null) { @@ -913,7 +914,7 @@ public class Codegen { break; } case TargetReturn ret: { - if (ret.expression() != null) { + if (ret.expression() != null && state.returnType != null) { generate(state, ret.expression()); convertTo(state, ret.expression().type(), state.returnType); boxPrimitive(state, state.returnType); diff --git a/src/test/java/targetast/TestCodegen.java b/src/test/java/targetast/TestCodegen.java index 46c4c834..4661bc28 100644 --- a/src/test/java/targetast/TestCodegen.java +++ b/src/test/java/targetast/TestCodegen.java @@ -37,7 +37,7 @@ public class TestCodegen { public static Map> generateClassFiles(String filename, ByteArrayClassLoader classLoader) throws IOException, ClassNotFoundException { var file = Path.of(System.getProperty("user.dir"), "/src/test/resources/bytecode/javFiles/", filename).toFile(); - var compiler = new JavaTXCompiler(file); + var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile())); var resultSet = compiler.typeInference(); var sourceFile = compiler.sourceFiles.get(file); var converter = new ASTToTargetAST(resultSet, sourceFile, classLoader); diff --git a/src/test/java/targetast/TestComplete.java b/src/test/java/targetast/TestComplete.java index ab42a8b6..215e5b5a 100644 --- a/src/test/java/targetast/TestComplete.java +++ b/src/test/java/targetast/TestComplete.java @@ -8,6 +8,7 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.TypeVariable; +import java.nio.file.Path; import java.util.Arrays; import java.util.Vector; diff --git a/src/test/resources/bytecode/javFiles/Box.jav b/src/test/resources/bytecode/javFiles/Box.jav index e83bde6d..4859d611 100644 --- a/src/test/resources/bytecode/javFiles/Box.jav +++ b/src/test/resources/bytecode/javFiles/Box.jav @@ -1,7 +1,3 @@ -class Box { - void m(A a) { } -} - class B { } class Box_Main extends B { m(b) { diff --git a/src/test/resources/bytecode/javFiles/Box.java b/src/test/resources/bytecode/javFiles/Box.java index e69de29b..581e7256 100644 --- a/src/test/resources/bytecode/javFiles/Box.java +++ b/src/test/resources/bytecode/javFiles/Box.java @@ -0,0 +1,3 @@ +class Box { + void m(A a) { } +} \ No newline at end of file