From 607405920d34b8b01220003adc6d20a2450ddcb7 Mon Sep 17 00:00:00 2001 From: Andreas Stadelmeier Date: Thu, 10 Mar 2022 22:49:01 +0100 Subject: [PATCH] Filter a <. b constraints at end of Unify. Create T <. Object constraints in TYPEMethod for ret and param types --- src/main/scala/hb/dhbw/TYPE.scala | 3 ++- src/main/scala/hb/dhbw/Unify.scala | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/scala/hb/dhbw/TYPE.scala b/src/main/scala/hb/dhbw/TYPE.scala index 9a3422c..981339e 100644 --- a/src/main/scala/hb/dhbw/TYPE.scala +++ b/src/main/scala/hb/dhbw/TYPE.scala @@ -52,7 +52,8 @@ object TYPE { private def TYPEMethod(method: Method, thisType: RefType, ast: List[Class]) = { val (rty, cons) = TYPEExpr(method.retExpr, List((thisType, "this")) ++ method.params, ast) - LessDot(rty, method.retType) :: cons + LessDot(rty, method.retType) :: LessDot(method.retType, RefType("Object", List())) :: + cons ++ method.params.map(_._1).map(LessDot(_, RefType("Object", List()))) } private def TYPEExpr(expr: Expr, localVars: List[(Type, String)], ast: List[Class]) : (Type, List[Constraint]) =expr match { diff --git a/src/main/scala/hb/dhbw/Unify.scala b/src/main/scala/hb/dhbw/Unify.scala index 5a6c278..9eea652 100644 --- a/src/main/scala/hb/dhbw/Unify.scala +++ b/src/main/scala/hb/dhbw/Unify.scala @@ -37,16 +37,20 @@ object Unify { def removeALessdotB(eq: Set[UnifyConstraint]): Set[UnifyConstraint] = { var ret = eq - val alessdotb = eq.filter(_ match{ + val alessdotb:Set[UnifyConstraint] = eq.filter(_ match{ case UnifyLessDot(UnifyTV(a), UnifyTV(b)) => true case _ => false }) + ret = ret.filter(it => !alessdotb.contains(it)) alessdotb.foreach(it => ret = subst(it.left.asInstanceOf[UnifyTV], it.right, ret)) - ret.filter(_ match{ + /* + .filter(_ match{ case UnifyEqualsDot(UnifyTV(a), UnifyTV(b)) => a != b case UnifyLessDot(UnifyTV(_), UnifyTV(_)) => false case _ => true - }) ++ alessdotb.map(_ match {case UnifyLessDot(a, b) => UnifyEqualsDot(a,b)}) + }) + */ + ret ++ alessdotb.map(_ match {case UnifyLessDot(a, b) => UnifyEqualsDot(a,b)}) } def unifyIterative(orCons: Set[Set[Set[UnifyConstraint]]], fc: FiniteClosure) : Set[Set[UnifyConstraint]] = {