Fix constructor overloads getting picked with the wrong arity
This commit is contained in:
parent
dcfafe5995
commit
e88d4428c5
17
resources/bytecode/javFiles/OLConstructor.jav
Normal file
17
resources/bytecode/javFiles/OLConstructor.jav
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -548,7 +548,9 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
for (var clazz : info.getAvailableClasses()) {
|
for (var clazz : info.getAvailableClasses()) {
|
||||||
if (clazz.getClassName().equals(info.getCurrentClass().getSuperClass().getName())) {
|
if (clazz.getClassName().equals(info.getCurrentClass().getSuperClass().getName())) {
|
||||||
for (var ctor : clazz.getConstructors()) {
|
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();
|
GenericsResolver resolver = getResolverInstance();
|
||||||
Set<Constraint<Pair>> oneMethodConstraints = generateConstraint(superCall, assumption, info, resolver);
|
Set<Constraint<Pair>> oneMethodConstraints = generateConstraint(superCall, assumption, info, resolver);
|
||||||
|
@ -825,4 +825,12 @@ public class TestComplete {
|
|||||||
|
|
||||||
assertNull(clazz.getDeclaredMethod("m").invoke(instance));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user