Fix Filter overloaded methods

This commit is contained in:
Andreas Stadelmeier 2021-12-13 05:55:37 +01:00
parent 9c4072aa81
commit 1df207c8c5
2 changed files with 30 additions and 4 deletions

View File

@ -56,9 +56,11 @@ object FJTypeinference {
if(m.params.size != superMethod.params.size){
false
}else{
var returnIsSub = finiteClosure.aIsSubtypeOfb(convertToFJType(getBound(m.retType)), convertToFJType(getBound(superMethod.retType)))
returnIsSub && m.params.zip(superMethod.params).foldLeft(true)((isSub, m2) =>
isSub && finiteClosure.aIsSubtypeOfb(convertToFJType(getBound(m2._1._1)), convertToFJType(getBound(m2._2._1))))
val returnIsSub = finiteClosure.aIsSubtypeOfb(convertToFJType(getBound(m.retType)), convertToFJType(getBound(superMethod.retType)))
val paramsAreSup = m.params.zip(superMethod.params).foldLeft(true)((isSub, m2) => {
isSub && finiteClosure.aIsSubtypeOfb(convertToFJType(getBound(m2._2._1)), convertToFJType(getBound(m2._1._1)))
})
returnIsSub && paramsAreSup
}
}
@ -69,7 +71,7 @@ object FJTypeinference {
if(ms.find(methodIsSupertype(_, m)).isDefined) { //If there is a method which is more general
ms //do not add this method
}else { //otherwise check if this method shadows another method
ms.filter(methodIsSupertype(m, _)) + m
ms.filter(!methodIsSupertype(m, _)) + m
}
})
})

View File

@ -102,8 +102,32 @@ class IntegrationTest extends FunSuite {
val result = FJTypeinference.typeinference(input)
println(result.map(it => Main.prettyPrintAST(it._2)))
}
test("PrincipalType") {
val input = "\nclass List<A extends Object> extends Object{\n A head;\n List<A> tail;\n add( a){\n return new List(a, this);\n }\n get(){\n return this.head;\n }\n}\n\nclass PrincipleType extends Object {\n function(a){\n return a.add(this).get();\n }\n}"
val result = FJTypeinference.typeinference(input)
println(result.map(it => Main.prettyPrintAST(it._2)))
}
/*
class List<A extends Object> extends Object{
A head;
List<A> tail;
add( a){
return new List(a, this);
}
get(){
return this.head;
}
}
class PrincipleType extends Object {
function(a){
return a.add(this).get();
}
}
class Function<A extends Object, B extends Object> extends Object{
B b;
B apply(A a){