Fix Filter overloaded methods
This commit is contained in:
parent
9c4072aa81
commit
1df207c8c5
@ -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
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -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){
|
||||
|
Loading…
Reference in New Issue
Block a user