Fix #311
All checks were successful
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 2m55s

This commit is contained in:
Daniel Holle 2024-04-08 13:51:49 +02:00
parent da74898f9d
commit f66b9099f3
3 changed files with 20 additions and 1 deletions

View File

@ -0,0 +1,10 @@
import java.lang.String;
public class Bug311 {
Bug311A i = new Bug311A();
public toString() {
return i.toString();
}
}
class Bug311A {}

View File

@ -79,8 +79,9 @@ public class ASTToTargetAST {
Optional<Method> findMethod(ClassOrInterface owner, String name, List<TargetType> argumentList) {
Optional<Method> method = Optional.empty();
while (method.isEmpty() && !owner.getClassName().toString().equals("java.lang.Object")) {
while (method.isEmpty()) {
method = owner.getMethods().stream().filter(m -> m.name.equals(name) && parameterEquals(m.getParameterList(), argumentList)).findFirst();
if (owner.getClassName().toString().equals("java.lang.Object")) break;
owner = compiler.getClass(owner.getSuperClass().getName());
}
return method;

View File

@ -1040,6 +1040,14 @@ public class TestComplete {
assertEquals(clazz.getDeclaredMethod("toString").invoke(instance), "3");
}
@Test
public void testBug311() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug311.jav");
var clazz = classFiles.get("Bug311");
var instance = clazz.getDeclaredConstructor().newInstance();
clazz.getDeclaredMethod("toString").invoke(instance);
}
@Test
public void testBug312() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug312.jav");