Merge branch 'master' into work

This commit is contained in:
JanUlrich 2022-06-14 17:36:22 +02:00
commit 80dcad7a13
3 changed files with 18 additions and 2 deletions

View File

@ -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))
}

View File

@ -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<A extends Object> 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)))
}
}

View File

@ -25,6 +25,16 @@ 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)
}
/*
test("Unify.step2") {
var step2 = Unify.step2(Set(UnifyLessDot(TypeVariable("a"), TypeVariable("b")),