diff --git a/resources/bytecode/javFiles/Bug306.jav b/resources/bytecode/javFiles/Bug306.jav new file mode 100644 index 00000000..d06ca677 --- /dev/null +++ b/resources/bytecode/javFiles/Bug306.jav @@ -0,0 +1,13 @@ +import java.lang.Integer; +import java.util.List; + +class Base { + m(List a) {} +} + +public class Bug306 extends Base { + @Override + m(List b) { + b.add(1); + } +} diff --git a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java index 412fbc54..3578ab02 100644 --- a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java +++ b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java @@ -52,7 +52,7 @@ public class ASTToTargetAST { return converter.result; } - record Generics(JavaGenerics javaGenerics, TxGenerics txGenerics) { + public record Generics(JavaGenerics javaGenerics, TxGenerics txGenerics) { } @@ -385,7 +385,7 @@ public class ASTToTargetAST { if (superMethod.isPresent()) { // If we find a super method to override, use its parameters and return types returnType = convert(superMethod.get().getReturnType(), this.generics.javaGenerics); - params = convert(superMethod.get().getParameterList(), this.generics.javaGenerics); + params = convert(superMethod.get().getParameterList(), method.getParameterList(), this.generics.javaGenerics); } List finalParams = params; @@ -404,6 +404,15 @@ public class ASTToTargetAST { return result; } + private List convert(ParameterList superList, ParameterList paraList, JavaGenerics generics) { + var list = new ArrayList(); + for (var i = 0; i < paraList.getFormalparalist().size(); i++) { + var param = paraList.getParameterAt(i); + list.add(new MethodParameter((TargetPattern) convert(param)).withType(convert(superList.getParameterAt(i).getType(), generics))); + } + return list; + } + protected TargetSwitch.Case convert(SwitchBlock block) { return new TargetSwitch.Case(block.getLabels().stream().map(this::convert).toList(), convert((Block) block), block.isExpression); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index c29e0468..81eac231 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -630,7 +630,6 @@ implements IFiniteClosure { i += 1; } - System.out.println(args); return args; } diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index f6e49b70..6000fcec 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -995,4 +995,11 @@ public class TestComplete { var clazz = classFiles.get("Bug301"); var instance = clazz.getDeclaredConstructor().newInstance(); } + + @Test + public void testBug306() throws Exception { + var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug306.jav"); + var clazz = classFiles.get("Bug306"); + var instance = clazz.getDeclaredConstructor().newInstance(); + } }