forked from JavaTX/JavaCompilerCore
Allow Void as return type for Lambdas
This commit is contained in:
parent
c51190feef
commit
1be27746e3
@ -28,12 +28,15 @@ public class FunNGenerator {
|
|||||||
private static final String objectSuperType = Type.getInternalName(Object.class).replace('.','/');
|
private static final String objectSuperType = Type.getInternalName(Object.class).replace('.','/');
|
||||||
private static final String objectSignature = applySignature(TargetType.Object);
|
private static final String objectSignature = applySignature(TargetType.Object);
|
||||||
|
|
||||||
|
private static final String VOID = "Ljava/lang/Void;";
|
||||||
|
|
||||||
public static class GenericParameters {
|
public static class GenericParameters {
|
||||||
int start;
|
int start;
|
||||||
public List<TargetType> parameters = new ArrayList<>();
|
public List<TargetType> parameters = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String applyDescriptor(TargetType type, GenericParameters gep) {
|
private static String applyDescriptor(TargetType type, GenericParameters gep) {
|
||||||
|
if (type == null) return VOID;
|
||||||
var res = "L" + type.getInternalName();
|
var res = "L" + type.getInternalName();
|
||||||
if (type instanceof TargetSpecializedType a) {
|
if (type instanceof TargetSpecializedType a) {
|
||||||
if (a.params().size() > 0) {
|
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)); }
|
private static String applyNameDescriptor(TargetType a){ return a instanceof TargetGenericType ? "LTPH;" : String.format("%s", applySignature(a)); }
|
||||||
|
|
||||||
public static String encodeType(TargetType type) {
|
public static String encodeType(TargetType type) {
|
||||||
|
if (type == null) return VOID;
|
||||||
return applyNameDescriptor(type).replace("/", "$").replace(";", "$_$");
|
return applyNameDescriptor(type).replace("/", "$").replace(";", "$_$");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,8 +398,7 @@ public class ASTToTargetAST {
|
|||||||
|
|
||||||
static TargetType flattenFunNType(List<TargetType> params, FunNGenerator.GenericParameters gep) {
|
static TargetType flattenFunNType(List<TargetType> params, FunNGenerator.GenericParameters gep) {
|
||||||
var newParams = new ArrayList<TargetType>();
|
var newParams = new ArrayList<TargetType>();
|
||||||
for (var i = 0; i < params.size(); i++) {
|
for (TargetType param : params) {
|
||||||
var param = params.get(i);
|
|
||||||
if (param instanceof TargetSpecializedType fn) {
|
if (param instanceof TargetSpecializedType fn) {
|
||||||
collectArguments(fn, newParams);
|
collectArguments(fn, newParams);
|
||||||
} else {
|
} else {
|
||||||
@ -422,7 +421,12 @@ public class ASTToTargetAST {
|
|||||||
if (name.equals("void"))
|
if (name.equals("void"))
|
||||||
return null;
|
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
|
if (name.matches("Fun\\d+\\$\\$")) { // TODO This seems like a bad idea
|
||||||
var className = FunNGenerator.getSpecializedClassName(FunNGenerator.getArguments(params), FunNGenerator.getReturnType(params));
|
var className = FunNGenerator.getSpecializedClassName(FunNGenerator.getArguments(params), FunNGenerator.getReturnType(params));
|
||||||
if (!usedFunNSuperTypes.contains(params.size())) {
|
if (!usedFunNSuperTypes.contains(params.size())) {
|
||||||
|
Loading…
Reference in New Issue
Block a user