Add test and fix constructors return value being used

This commit is contained in:
Victorious3 2023-03-08 14:59:40 +01:00
parent cdd4cd9968
commit 04b509613f
3 changed files with 41 additions and 2 deletions

View File

@ -0,0 +1,32 @@
import java.util.Vector;
import java.lang.Boolean;
import java.lang.Object;
class Pair<U, T> {
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<? extends Eq> b)
{
//this.compare(p); //1, type incorrect
this.compare(this.make(b)); //2, OK
}
*/
}

View File

@ -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

View File

@ -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();
}
}