From 2d128362624dc527f8485a233ca7ca1462e5934d Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 14 Jun 2022 11:17:02 +0200 Subject: [PATCH 1/2] Add Test --- src/test/scala/UnifyTest.scala | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/scala/UnifyTest.scala b/src/test/scala/UnifyTest.scala index 9351937..95624c8 100644 --- a/src/test/scala/UnifyTest.scala +++ b/src/test/scala/UnifyTest.scala @@ -25,6 +25,18 @@ class UnifyTest extends FunSuite { println(result) } + test("example"){ + val input : Set[UnifyConstraint] = Set(UnifyEqualsDot(UnifyTV("b"), UnifyTV("y")), + UnifyLessDot(UnifyRefType("Pair", List(UnifyRefType("X", List()), UnifyRefType("Y", List()))), UnifyRefType("Pair", List(UnifyTV("w"), UnifyTV("y")))), + UnifyLessDot(UnifyRefType("Pair", List(UnifyTV("d"), UnifyTV("e"))), UnifyTV("A")), + UnifyLessDot(UnifyTV("F"), UnifyTV("d")), + UnifyLessDot(UnifyTV("b"), UnifyTV("e")), + UnifyLessDot(UnifyTV("F"), UnifyRefType("Object", List()))) + val result = Unify.unifyIterative(Set(Set(input)), new FiniteClosure(Set((FJNamedType("Pair", List(FJNamedType("X", List()),FJNamedType("X", List()))), FJNamedType("Object", List()))))) + println(result) + //assert(result.contains(UnifyEqualsDot(UnifyTV("a"), UnifyTV("b")))) + //assert(result.contains(UnifyEqualsDot(UnifyTV("b"), UnifyTV("a")))) + } /* test("Unify.step2") { var step2 = Unify.step2(Set(UnifyLessDot(TypeVariable("a"), TypeVariable("b")), From 8d3c6992ac36faaf361eec07c1bdd38f0f3dbe67 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 14 Jun 2022 17:36:11 +0200 Subject: [PATCH 2/2] Add Test --- src/main/scala/hb/dhbw/InsertTypes.scala | 3 +-- src/test/scala/IntegrationTest.scala | 7 +++++++ src/test/scala/UnifyTest.scala | 2 -- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/scala/hb/dhbw/InsertTypes.scala b/src/main/scala/hb/dhbw/InsertTypes.scala index 94ec681..c4d9622 100644 --- a/src/main/scala/hb/dhbw/InsertTypes.scala +++ b/src/main/scala/hb/dhbw/InsertTypes.scala @@ -11,7 +11,7 @@ object InsertTypes { case v => v } def sigma(x: UnifyType): Type = { x match { - case UnifyTV(n) => { + case UnifyTV(n) => val to = solvedCons.find(_.left == x).get to match { case UnifyEqualsDot(UnifyTV(_), UnifyTV(x)) => GenericType(x) @@ -19,7 +19,6 @@ object InsertTypes { case UnifyEqualsDot(UnifyTV(_), UnifyRefType(n, ps)) => RefType(n, ps.map(this.sigma(_))) case UnifyLessDot(UnifyTV(x), UnifyRefType(n, ps)) => GenericType(x) } - } case UnifyRefType(n, List()) => if(genericNames.contains(n)) GenericType(n) else RefType(n, List()) case UnifyRefType(n, ps) => RefType(n, ps.map(sigma)) } diff --git a/src/test/scala/IntegrationTest.scala b/src/test/scala/IntegrationTest.scala index 37dee87..5d865dc 100644 --- a/src/test/scala/IntegrationTest.scala +++ b/src/test/scala/IntegrationTest.scala @@ -96,4 +96,11 @@ class IntegrationTest extends FunSuite { assert(result.isRight) println(result.map(it => Main.prettyPrintAST(it))) } + + test("pairAdd.twoTimes") { + val input = "class Pair extends Object{\n A fst;\n \n setfst(p) {\n return p;\n }\n }\n\n class Example extends Object{\n\n m(p){\n return p.setfst(p.setfst(this));\n }\n }" + val result = FJTypeinference.typeinference(input) + assert(result.isRight) + println(result.map(it => Main.prettyPrintAST(it))) + } } diff --git a/src/test/scala/UnifyTest.scala b/src/test/scala/UnifyTest.scala index 95624c8..b76418d 100644 --- a/src/test/scala/UnifyTest.scala +++ b/src/test/scala/UnifyTest.scala @@ -34,8 +34,6 @@ class UnifyTest extends FunSuite { UnifyLessDot(UnifyTV("F"), UnifyRefType("Object", List()))) val result = Unify.unifyIterative(Set(Set(input)), new FiniteClosure(Set((FJNamedType("Pair", List(FJNamedType("X", List()),FJNamedType("X", List()))), FJNamedType("Object", List()))))) println(result) - //assert(result.contains(UnifyEqualsDot(UnifyTV("a"), UnifyTV("b")))) - //assert(result.contains(UnifyEqualsDot(UnifyTV("b"), UnifyTV("a")))) } /* test("Unify.step2") {