Let lambda functions use Object instead of generic parameters

This commit is contained in:
Victorious3 2023-03-01 10:49:03 +01:00
parent 374d2e811b
commit 1ad4cfcb21

View File

@ -705,11 +705,15 @@ public class Codegen {
} else {
var name = "lambda$" + lambdaCounter++;
var parameters = new ArrayList<>(lambda.captures());
parameters.addAll(lambda.params());
parameters.addAll(lambda.params().stream()
.map(param -> param.type() instanceof TargetGenericType ? new MethodParameter(TargetType.Object, param.name()) : param)
.toList());
impl = new TargetMethod(
0, name, Set.of(), Set.of(),
parameters, lambda.returnType(), lambda.block()
parameters,
lambda.returnType() instanceof TargetGenericType ? TargetType.Object : lambda.returnType(),
lambda.block()
);
generateMethod(impl);
lambdas.put(lambda, impl);
@ -736,7 +740,9 @@ public class Codegen {
var params = new ArrayList<TargetType>();
params.add(new TargetRefType(clazz.qualifiedName()));
params.addAll(lambda.captures().stream().map(MethodParameter::type).toList());
params.addAll(lambda.captures().stream()
.map(MethodParameter::type)
.toList());
var descriptor = TargetMethod.getDescriptor(lambda.type(), params.toArray(TargetType[]::new));
mv.visitVarInsn(ALOAD, 0);