From edf85dca7f227ba4f42f4677707ac0e3aa11a4eb Mon Sep 17 00:00:00 2001 From: Victorious3 Date: Tue, 9 Aug 2022 12:59:23 +0200 Subject: [PATCH] Fix Tph4-6 --- .../target/generate/ASTToTargetAST.java | 15 ++++++++++++++- src/test/java/targetast/TestComplete.java | 6 ++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java index bd122e55b..61be1e8c9 100644 --- a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java +++ b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.target.generate; +import com.google.j2objc.annotations.LoopTranslation; import de.dhbwstuttgart.bytecode.funN.FunNGenerator; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.parser.NullToken; @@ -145,7 +146,7 @@ public class ASTToTargetAST { findTypeVariables(field.getType(), typeVariablesOfFields); } - findTypeVariables(method.getReturnType(), typeVariables); + //findTypeVariables(method.getReturnType(), typeVariables); for (var arg : method.getParameterList().getFormalparalist()) { findTypeVariables(arg.getType(), typeVariables); } @@ -155,6 +156,15 @@ public class ASTToTargetAST { public void visit(LocalVarDecl localVarDecl) { findTypeVariables(localVarDecl.getType(), typeVariables); } + + @Override + public void visit(MethodCall methodCall) { + super.visit(methodCall); + findTypeVariables(methodCall.getType(), typeVariables); + } + + @Override + public void visit(Assign assign) {} }); // Type variables with bounds that are also type variables of the method @@ -221,6 +231,7 @@ public class ASTToTargetAST { for (var pair2 : simplifiedConstraints) { if (!(pair2.right.equals(tph2) && pair2.left.equals(type))) continue; + if (tph.equals(tph2)) continue; var newPair = new PairTPHsmallerTPH(tph, tph2); newPairs.add(newPair); @@ -572,6 +583,8 @@ public class ASTToTargetAST { for (var i = 0; i < pars.size(); i++) { var type1 = convert(pars.get(i).getType()); var type2 = convert(arguments.get(i).getType()); + if (type2 instanceof TargetGenericType && type1 instanceof TargetGenericType) + return true; if (!type1.equals(type2)) return false; } diff --git a/src/test/java/targetast/TestComplete.java b/src/test/java/targetast/TestComplete.java index d0e075403..ab45a81fb 100644 --- a/src/test/java/targetast/TestComplete.java +++ b/src/test/java/targetast/TestComplete.java @@ -349,6 +349,12 @@ public class TestComplete { var instance = classFiles.get("Tph3").getDeclaredConstructor().newInstance(); } + @Test + public void tph4Test() throws Exception { + var classFiles = generateClassFiles("Tph4.jav", new ByteArrayClassLoader()); + var instance = classFiles.get("Tph4").getDeclaredConstructor().newInstance(); + } + @Test public void tph5Test() throws Exception { var classFiles = generateClassFiles("Tph5.jav", new ByteArrayClassLoader());