From e5ff08e0dfc81e17841d1b5f58366014468176de Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 14 Apr 2023 15:12:43 +0200 Subject: [PATCH] modified: resources/bytecode/javFiles/Scalar.jav modified: src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java ? extends ty { i=i+1; } } - + mul(v) { var ret = 0; var i = 0; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index d120e483..5d60428b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -13,6 +13,7 @@ import java.util.function.Function; import java.util.stream.Collectors; import de.dhbwstuttgart.exceptions.DebugException; +import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; @@ -390,26 +391,51 @@ public class RuleSet implements IRuleSet{ if((pair.getPairOp() != PairOperator.SMALLERDOT) && (pair.getPairOp() != PairOperator.SMALLERNEQDOT)) return false; - if (pair.getPairOp() == PairOperator.SMALLERNEQDOT) { - UnifyType lhs = pair.getLhsType(); - UnifyType rhs = pair.getRhsType(); - if (lhs instanceof WildcardType) { - lhs = ((WildcardType)lhs).getWildcardedType(); - } - if (rhs instanceof WildcardType) { - rhs = ((WildcardType)rhs).getWildcardedType(); - } - - if (lhs.equals(rhs)){ - return false; - } + UnifyType lhsType = pair.getLhsType(); + UnifyType rhsType = pair.getRhsType(); + + /* + * ty <. ? extends ty' is wrong + */ + if (rhsType instanceof ExtendsType) { + return false; + } + + /* + * ? super ty <. ty' is wrong + * except Ty' = Object or ty' = ? super Object + */ + if ((lhsType instanceof SuperType) && + (!(rhsType.equals(new ReferenceType("java.lang.Object", false)))) && + !(rhsType.equals(new SuperType (new ReferenceType("java.lang.Object", false))))) { + return false; + } + + /* + * ? extends ty <. ty' is equivalent to ty < ty' + */ + if (lhsType instanceof ExtendsType) { + lhsType = ((WildcardType)lhsType).getWildcardedType(); + } + + /* + * ty <. ? super ty' ist equivalent to ty <. ty' + */ + if (rhsType instanceof SuperType) { + rhsType = ((WildcardType)rhsType).getWildcardedType(); + } + + /* + * SMALLERNEQDOT => type must not be equal + */ + if (pair.getPairOp() == PairOperator.SMALLERNEQDOT && lhsType.equals(rhsType)){ + return false; } - UnifyType lhsType = pair.getLhsType(); if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType)) return false; - UnifyType rhsType = pair.getRhsType(); + if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType)) return false;