Taking the super methods parameters should only happen for the types, fix #306
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 2m23s

This commit is contained in:
Daniel Holle 2024-03-25 13:43:30 +01:00
parent e07521d9b6
commit 7cb0e9dbb7
4 changed files with 31 additions and 3 deletions

View File

@ -0,0 +1,13 @@
import java.lang.Integer;
import java.util.List;
class Base {
m(List<Integer> a) {}
}
public class Bug306 extends Base {
@Override
m(List<Integer> b) {
b.add(1);
}
}

View File

@ -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<MethodParameter> finalParams = params;
@ -404,6 +404,15 @@ public class ASTToTargetAST {
return result;
}
private List<MethodParameter> convert(ParameterList superList, ParameterList paraList, JavaGenerics generics) {
var list = new ArrayList<MethodParameter>();
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);
}

View File

@ -630,7 +630,6 @@ implements IFiniteClosure {
i += 1;
}
System.out.println(args);
return args;
}

View File

@ -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();
}
}