diff --git a/resources/bytecode/javFiles/Pair.jav b/resources/bytecode/javFiles/Pair.jav new file mode 100644 index 000000000..aacb8d4f3 --- /dev/null +++ b/resources/bytecode/javFiles/Pair.jav @@ -0,0 +1,32 @@ +import java.util.Vector; +import java.lang.Boolean; +import java.lang.Object; + +class Pair { + U a; + T b; + + make(x) { + var ret = new Pair<>(); + ret.a = x.elementAt(0); + ret.b = x.elementAt(1); + return ret; + } + /* + eq(a, b) { + b = a; + return a == b; + } + + compare( p) { + return eq(p.a, p.b); + //return p.a == p.b; + } + + void m(Pair p, List b) + { + //this.compare(p); //1, type incorrect + this.compare(this.make(b)); //2, OK + } +*/ +} \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java index 86c94f7e9..c628bbce7 100644 --- a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java +++ b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java @@ -445,7 +445,6 @@ public class ASTToTargetAST { addToPairs(result, minimalPair); } - // All unbounded type variables (bounds not in method) outer: for (var typeVariable : typeVariables) { @@ -482,7 +481,8 @@ public class ASTToTargetAST { typeVariablesOfClass.add((TypePlaceholder) pair.getLeft()); } - typeVariables.addAll(findTypeVariables(method.getReturnType(), equality)); + if (!(method instanceof Constructor)) + typeVariables.addAll(findTypeVariables(method.getReturnType(), equality)); for (var arg : method.getParameterList().getFormalparalist()) { typeVariables.addAll(findTypeVariables(arg.getType(), equality)); } @@ -502,6 +502,7 @@ public class ASTToTargetAST { @Override public void visit(Assign assign) {} }); + System.out.println("4: " + typeVariables); } // Family of generated Generics diff --git a/src/test/java/targetast/TestComplete.java b/src/test/java/targetast/TestComplete.java index b8fc0b8d9..b1773e150 100644 --- a/src/test/java/targetast/TestComplete.java +++ b/src/test/java/targetast/TestComplete.java @@ -598,4 +598,10 @@ public class TestComplete { var classFiles = generateClassFiles("OLFun2.jav", new ByteArrayClassLoader()); var instance = classFiles.get("OLFun2").getDeclaredConstructor().newInstance(); } + + @Test + public void pairTest() throws Exception { + var classFiles = generateClassFiles("Pair.jav", new ByteArrayClassLoader()); + var instance = classFiles.get("Pair").getDeclaredConstructor().newInstance(); + } }