Fix #326, convert captures to correct types
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 3m9s

This commit is contained in:
Daniel Holle 2024-04-30 16:55:40 +02:00
parent 2c66a1d6e6
commit df2ec4b1ba
4 changed files with 20 additions and 5 deletions

View File

@ -0,0 +1,8 @@
import java.lang.Integer;
public class Bug326 {
public Bug326() {
var func = x -> y -> x * y;
return func.apply(3).apply(4);
}
}

View File

@ -784,9 +784,12 @@ public class Codegen {
var descriptor = TargetMethod.getDescriptor(state.contextType, params.toArray(TargetType[]::new));
mv.visitVarInsn(ALOAD, 0);
for (var capture : lambda.captures()) {
for (var index = 0; index < lambda.captures().size(); index++) {
var capture = lambda.captures().get(index);
var pattern = (TargetTypePattern) capture.pattern();
mv.visitVarInsn(ALOAD, state.scope.get(pattern.name()).index);
var variable = state.scope.get(pattern.name());
mv.visitVarInsn(ALOAD, variable.index);
mv.visitTypeInsn(CHECKCAST, capture.pattern().type().getInternalName());
}
mv.visitInvokeDynamicInsn(methodName, descriptor, bootstrap, Type.getType(signature.getSignature()), handle, Type.getType(signature.getDescriptor()));

View File

@ -592,7 +592,6 @@ public class TYPEStmt implements StatementVisitor {
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);
System.out.println(params);
GenericsResolver resolver = getResolverInstance();
Set<Constraint<Pair>> oneMethodConstraints = generateConstraint(superCall, assumption, info, resolver);
@ -683,7 +682,6 @@ public class TYPEStmt implements StatementVisitor {
extendsMethodConstraint.addAll(parameterContraints);
Set<Pair> methodSignatureConstraint = generatemethodSignatureConstraint(forMethod, assumption, info, resolver);
System.out.println(methodSignatureConstraint);
//System.out.println("methodSignatureConstraint: " + methodSignatureConstraint);
//System.out.println("methodConstraint: " + methodConstraint);
@ -718,7 +716,6 @@ public class TYPEStmt implements StatementVisitor {
Set<Pair> ret = new HashSet<>();
for (int i = 0; i < foMethod.arglist.getArguments().size(); i++) {
System.out.println(foMethod.signature);
// Zuordnung von MethoCall.signature (Argumenttypen) zu der Argumenttypen der ausgewaehlten Methode (assumption.params)
ret.add(new Pair(foMethod.signature.get(i), assumption.getArgTypes().get(i), PairOperator.EQUALSDOT));

View File

@ -1085,6 +1085,13 @@ public class TestComplete {
assertEquals(res, List.of(6, 7, 8));
}
@Test
public void testBug326() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug326.jav");
var clazz = classFiles.get("Bug326");
var instance = clazz.getDeclaredConstructor().newInstance();
}
@Test
public void testBug328() throws Exception {
var loader = new ByteArrayClassLoader();