Allow Void as return type for Lambdas

This commit is contained in:
Daniel Holle 2023-10-31 14:26:43 +01:00
parent c51190feef
commit 1be27746e3
2 changed files with 11 additions and 3 deletions

View File

@ -28,12 +28,15 @@ public class FunNGenerator {
private static final String objectSuperType = Type.getInternalName(Object.class).replace('.','/');
private static final String objectSignature = applySignature(TargetType.Object);
private static final String VOID = "Ljava/lang/Void;";
public static class GenericParameters {
int start;
public List<TargetType> parameters = new ArrayList<>();
}
private static String applyDescriptor(TargetType type, GenericParameters gep) {
if (type == null) return VOID;
var res = "L" + type.getInternalName();
if (type instanceof TargetSpecializedType a) {
if (a.params().size() > 0) {
@ -62,6 +65,7 @@ public class FunNGenerator {
private static String applyNameDescriptor(TargetType a){ return a instanceof TargetGenericType ? "LTPH;" : String.format("%s", applySignature(a)); }
public static String encodeType(TargetType type) {
if (type == null) return VOID;
return applyNameDescriptor(type).replace("/", "$").replace(";", "$_$");
}

View File

@ -398,8 +398,7 @@ public class ASTToTargetAST {
static TargetType flattenFunNType(List<TargetType> params, FunNGenerator.GenericParameters gep) {
var newParams = new ArrayList<TargetType>();
for (var i = 0; i < params.size(); i++) {
var param = params.get(i);
for (TargetType param : params) {
if (param instanceof TargetSpecializedType fn) {
collectArguments(fn, newParams);
} else {
@ -422,7 +421,12 @@ public class ASTToTargetAST {
if (name.equals("void"))
return null;
var params = refType.getParaList().stream().map(type -> convert(type, generics)).toList();
var params = refType.getParaList().stream().map(type -> {
var res = convert(type, generics);
if (res == null) res = new TargetRefType("java.lang.Void");
return res;
}).toList();
if (name.matches("Fun\\d+\\$\\$")) { // TODO This seems like a bad idea
var className = FunNGenerator.getSpecializedClassName(FunNGenerator.getArguments(params), FunNGenerator.getReturnType(params));
if (!usedFunNSuperTypes.contains(params.size())) {