diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/TypeInferenceTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/TypeInferenceTest.java index 4d1f1011bf..ed31b98676 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/TypeInferenceTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/TypeInferenceTest.java @@ -30,8 +30,10 @@ public class TypeInferenceTest { private JavaTypeDefinition integer = JavaTypeDefinition.forClass(Integer.class); private JavaTypeDefinition primitiveInt = JavaTypeDefinition.forClass(int.class); private JavaTypeDefinition generic = JavaTypeDefinition.forClass(Map.class, number, integer); - private Variable a = new Variable(); - private Variable b = new Variable(); + private Variable alpha = new Variable(); + private Variable beta = new Variable(); + JavaTypeDefinition s = JavaTypeDefinition.forClass(int.class); + JavaTypeDefinition t = JavaTypeDefinition.forClass(double.class); @Test public void testEqualityReduceProperVsProper() { @@ -47,22 +49,22 @@ public class TypeInferenceTest { public void testEqualityReduceVariableVsNotPrimitive() { // Otherwise, if S is an inference variable, α, and T is not a primitive type, the constraint reduces to // the bound α = T. - List result = new Constraint(a, number, EQUALITY).reduce(); + List result = new Constraint(alpha, number, EQUALITY).reduce(); assertEquals(result.size(), 1); - testBoundOrConstraint(result.get(0), a, number, EQUALITY, Bound.class); + testBoundOrConstraint(result.get(0), alpha, number, EQUALITY, Bound.class); } @Test public void testEqualityReduceNotPrimitiveVsVariable() { // Otherwise, if T is an inference variable, α, and S is not a primitive type, the constraint reduces // to the bound S = α. - List result = new Constraint(number, a, EQUALITY).reduce(); + List result = new Constraint(number, alpha, EQUALITY).reduce(); assertEquals(result.size(), 1); - testBoundOrConstraint(result.get(0), number, a, EQUALITY, Bound.class); + testBoundOrConstraint(result.get(0), number, alpha, EQUALITY, Bound.class); - result = new Constraint(a, b, EQUALITY).reduce(); + result = new Constraint(alpha, beta, EQUALITY).reduce(); assertEquals(result.size(), 1); - testBoundOrConstraint(result.get(0), a, b, EQUALITY, Bound.class); + testBoundOrConstraint(result.get(0), alpha, beta, EQUALITY, Bound.class); } @Test @@ -80,7 +82,8 @@ public class TypeInferenceTest { public void testEqualityReduceArrayTypes() { // Otherwise, if S and T are array types, S'[] and T'[], the constraint reduces to ‹S' = T'›. List result = new Constraint(JavaTypeDefinition.forClass(Number[].class), - JavaTypeDefinition.forClass(Integer[].class), EQUALITY).reduce(); + JavaTypeDefinition.forClass(Integer[].class), EQUALITY) + .reduce(); assertEquals(result.size(), 1); testBoundOrConstraint(result.get(0), number, integer, EQUALITY, Constraint.class); } @@ -105,21 +108,21 @@ public class TypeInferenceTest { @Test public void testSubtypeReduceVariableVsAny() { // Otherwise, if S is an inference variable, α, the constraint reduces to the bound α <: T. - List result = new Constraint(a, integer, SUBTYPE).reduce(); + List result = new Constraint(alpha, integer, SUBTYPE).reduce(); assertEquals(result.size(), 1); - testBoundOrConstraint(result.get(0), a, integer, SUBTYPE, Bound.class); + testBoundOrConstraint(result.get(0), alpha, integer, SUBTYPE, Bound.class); } @Test public void testSubtypeReduceAnyVsVariable() { // Otherwise, if T is an inference variable, α, the constraint reduces to the bound S <: α. - List result = new Constraint(integer, a, SUBTYPE).reduce(); + List result = new Constraint(integer, alpha, SUBTYPE).reduce(); assertEquals(result.size(), 1); - testBoundOrConstraint(result.get(0), integer, a, SUBTYPE, Bound.class); + testBoundOrConstraint(result.get(0), integer, alpha, SUBTYPE, Bound.class); - result = new Constraint(a, b, SUBTYPE).reduce(); + result = new Constraint(alpha, beta, SUBTYPE).reduce(); assertEquals(result.size(), 1); - testBoundOrConstraint(result.get(0), a, b, SUBTYPE, Bound.class); + testBoundOrConstraint(result.get(0), alpha, beta, SUBTYPE, Bound.class); } @@ -167,13 +170,13 @@ public class TypeInferenceTest { @Test public void testLooseInvocationAnythingElse() { // Otherwise, the constraint reduces to ‹S<:T›. - List result = new Constraint(number, a, LOOSE_INVOCATION).reduce(); + List result = new Constraint(number, alpha, LOOSE_INVOCATION).reduce(); assertEquals(result.size(), 1); - testBoundOrConstraint(result.get(0), number, a, SUBTYPE, Constraint.class); + testBoundOrConstraint(result.get(0), number, alpha, SUBTYPE, Constraint.class); - result = new Constraint(a, number, LOOSE_INVOCATION).reduce(); + result = new Constraint(alpha, number, LOOSE_INVOCATION).reduce(); assertEquals(result.size(), 1); - testBoundOrConstraint(result.get(0), a, number, SUBTYPE, Constraint.class); + testBoundOrConstraint(result.get(0), alpha, number, SUBTYPE, Constraint.class); } @Test @@ -198,14 +201,8 @@ public class TypeInferenceTest { } @Test - public void testIncorporation() { + public void testIncorporationEqualityAndEquality() { List result; - List current = new ArrayList<>(); - List newBounds = new ArrayList<>(); - - JavaTypeDefinition s = JavaTypeDefinition.forClass(int.class); - JavaTypeDefinition t = JavaTypeDefinition.forClass(double.class); - Variable alpha = a; // ### Original rule 1. : α = S and α = T imply ‹S = T› result = incorporationResult(new Bound(alpha, s, EQUALITY), new Bound(alpha, t, EQUALITY)); @@ -226,7 +223,11 @@ public class TypeInferenceTest { result = incorporationResult(new Bound(s, alpha, EQUALITY), new Bound(t, alpha, EQUALITY)); assertEquals(result.size(), 1); testBoundOrConstraint(result.get(0), s, t, EQUALITY, Constraint.class); + } + @Test + public void testIncorporationEqualityAndSubtypeLeftVariable() { + List result; // ### Original rule 2. : α = S and α <: T imply ‹S <: T› result = incorporationResult(new Bound(alpha, s, EQUALITY), new Bound(alpha, t, SUBTYPE)); @@ -247,7 +248,11 @@ public class TypeInferenceTest { result = incorporationResult(new Bound(alpha, t, SUBTYPE), new Bound(s, alpha, EQUALITY)); assertEquals(result.size(), 1); testBoundOrConstraint(result.get(0), s, t, SUBTYPE, Constraint.class); + } + @Test + public void testIncorporationEqualityAndSubtypeRightVariable() { + List result; // ### Original rule 3. : α = S and T <: α imply ‹T <: S› result = incorporationResult(new Bound(alpha, s, EQUALITY), new Bound(t, alpha, SUBTYPE)); @@ -268,8 +273,12 @@ public class TypeInferenceTest { result = incorporationResult(new Bound(t, alpha, SUBTYPE), new Bound(s, alpha, EQUALITY)); assertEquals(result.size(), 1); testBoundOrConstraint(result.get(0), t, s, SUBTYPE, Constraint.class); + } - + @Test + public void testIncorporationSubtypeAndSubtype() { + List result; + // ### Original rule 4. : S <: α and α <: T imply ‹S <: T› result = incorporationResult(new Bound(s, alpha, EQUALITY), new Bound(alpha, t, SUBTYPE)); assertEquals(result.size(), 1);