diff --git a/src/main/scala/hb/dhbw/FJTypeinference.scala b/src/main/scala/hb/dhbw/FJTypeinference.scala
index 752a603..e7ffc4f 100644
--- a/src/main/scala/hb/dhbw/FJTypeinference.scala
+++ b/src/main/scala/hb/dhbw/FJTypeinference.scala
@@ -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
}
})
})
diff --git a/src/test/scala/IntegrationTest.scala b/src/test/scala/IntegrationTest.scala
index 88eab65..99fc8ee 100644
--- a/src/test/scala/IntegrationTest.scala
+++ b/src/test/scala/IntegrationTest.scala
@@ -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 extends Object{\n A head;\n List 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 extends Object{
+ A head;
+ List 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 extends Object{
B b;
B apply(A a){