diff --git a/src/main/scala/hb/dhbw/CartesianProduct.scala b/src/main/scala/hb/dhbw/CartesianProduct.scala index 65a759b..0053abd 100644 --- a/src/main/scala/hb/dhbw/CartesianProduct.scala +++ b/src/main/scala/hb/dhbw/CartesianProduct.scala @@ -6,7 +6,7 @@ class CartesianProduct[A](private val setOfSets: List[List[A]]){ private var max: Long = 1 private var i: Long = 0 - def this(setOfSets: Set[Set[A]]){ + def this(setOfSets: Set[Set[A]]) { this(setOfSets.map(_.toList).toList) var base: Long = 1 sizes = this.setOfSets.map(_.size) @@ -15,16 +15,6 @@ class CartesianProduct[A](private val setOfSets: List[List[A]]){ base = base * size }) max = base - /* - sizes = constraints.stream().map(OderConstraint::getSize).collect(Collectors.toList()); - long base = 1; - for(int size : sizes){ - bases.add(base); - base *= size; - } - i = 0; - max = estimateSize() - 1; - */ } def hasNext() = i < max @@ -38,14 +28,4 @@ class CartesianProduct[A](private val setOfSets: List[List[A]]){ i = i + 1 ret.toSet } - /* - private Set get(long num){ - Set ret = new HashSet<>(); - Iterator baseIt = bases.iterator(); - for(OderConstraint constraint : constraints){ - ret.addAll(constraint.get((int) ((num/baseIt.next())%constraint.getSize()))); - } - return ret; - } - */ } diff --git a/src/main/scala/hb/dhbw/Unify.scala b/src/main/scala/hb/dhbw/Unify.scala index daef481..9604c26 100644 --- a/src/main/scala/hb/dhbw/Unify.scala +++ b/src/main/scala/hb/dhbw/Unify.scala @@ -163,7 +163,7 @@ object Unify { while(iterator.hasNext && circle.isEmpty){ val newAdd = iterator.next() if(newAdd.right.equals(graph.head.left)){ - circle = graph ++ List(newAdd) + circle = graph :+ newAdd }else{ circle = findCircle(graph ++ List(newAdd)) } @@ -194,7 +194,7 @@ object Unify { }).isDefined def substStep(eq: Set[UnifyConstraint]) = eq.find(c => c match { case UnifyEqualsDot(TypeVariable(a), RefType(n, p)) => !paramsContain(TypeVariable(a), RefType(n,p)) - case UnifyEqualsDot(TypeVariable(a), TypeVariable(b)) => true + case UnifyEqualsDot(TypeVariable(a), TypeVariable(b)) => !a.equals(b) case _ => false }).map(c => (subst(c.left.asInstanceOf[TypeVariable], c.right, eq), Some(c))).getOrElse((eq, None)) diff --git a/src/test/scala/IntegrationTest.scala b/src/test/scala/IntegrationTest.scala index 0d636b0..8b54900 100644 --- a/src/test/scala/IntegrationTest.scala +++ b/src/test/scala/IntegrationTest.scala @@ -27,4 +27,14 @@ class IntegrationTest extends FunSuite { println(result.map(Main.prettyPrint(_))) } + test("IdentCallExample"){ + val result = FJTypeinference.typeinference("class Test extends Object{\n\n m(a,b){return this.m(a);\n}\nm(a){return a;}\n}") + println(result.map(Main.prettyPrint(_))) + } + + test("IdentRecursive"){ + val result = FJTypeinference.typeinference("class Test extends Object{\n\nm(a){\nreturn this.m(a);\n}\n}") + println(result.map(Main.prettyPrint(_))) + } + }