Fix constructor overloads getting picked with the wrong arity

This commit is contained in:
Daniel Holle 2024-02-05 15:24:06 +01:00
parent dcfafe5995
commit e88d4428c5
3 changed files with 28 additions and 1 deletions

View File

@ -0,0 +1,17 @@
import java.lang.Integer;
public class Parent {
public Integer x;
public Parent(Integer a) {
this.x = a;
}
public Parent() {}
}
class Child extends Parent {
Child() {
super(3);
}
}

View File

@ -548,7 +548,9 @@ public class TYPEStmt implements StatementVisitor {
for (var clazz : info.getAvailableClasses()) {
if (clazz.getClassName().equals(info.getCurrentClass().getSuperClass().getName())) {
for (var ctor : clazz.getConstructors()) {
var assumption = new MethodAssumption(null, new Void(new NullToken()), convertParams(ctor.getParameterList(), info), createTypeScope(clazz, ctor), ctor.isInherited);
var params = convertParams(ctor.getParameterList(), info);
if (params.size() != superCall.arglist.getArguments().size()) continue;
var assumption = new MethodAssumption(null, new Void(new NullToken()), params, createTypeScope(clazz, ctor), ctor.isInherited);
GenericsResolver resolver = getResolverInstance();
Set<Constraint<Pair>> oneMethodConstraints = generateConstraint(superCall, assumption, info, resolver);

View File

@ -825,4 +825,12 @@ public class TestComplete {
assertNull(clazz.getDeclaredMethod("m").invoke(instance));
}
@Test
public void testOLConstructor() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "OLConstructor.jav");
var clazz = classFiles.get("Child");
var instance = clazz.getDeclaredConstructor().newInstance();
assertEquals(clazz.getSuperclass().getDeclaredField("x").get(instance), 3);
}
}