Skip to content

Commit 89dc262

Browse files
committed
test type inference against unparameterized class
Interfaces and Classes (without type variables) will face a similar problem as Objects (which was earlier solved)
1 parent 4e111b4 commit 89dc262

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

‎scijava/scijava-ops/src/test/java/org/scijava/ops/matcher/InferTypeVariablesTest.java‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,50 @@ public <O extends Number> void testInferOToAny()
293293

294294
assertEquals(expected, typeAssigns);
295295
}
296+
297+
@Test
298+
public <O extends Number> void testInferOToAnyWithInterface()
299+
throws TypeInferenceException
300+
{
301+
final Type type = new Nil<ArrayList<O>>() {}.getType();
302+
final Type inferFrom = Cloneable.class;
303+
304+
Map<TypeVariable<?>, MatchingUtils.TypeMapping> typeAssigns =
305+
new HashMap<>();
306+
MatchingUtils.inferTypeVariables(type, inferFrom, typeAssigns);
307+
308+
// We expect O = Any
309+
TypeVariable<?> typeVarO = (TypeVariable<?>) new Nil<O>() {}.getType();
310+
Map<TypeVariable<?>, MatchingUtils.TypeMapping> expected = new HashMap<>();
311+
expected.put(typeVarO, new TypeMapping(typeVarO, new Any(), true));
312+
313+
assertEquals(expected, typeAssigns);
314+
}
315+
316+
@Test
317+
public <O extends Number> void testInferOToAnyWithClass()
318+
throws TypeInferenceException
319+
{
320+
final Type type = new Nil<TypedBar<O>>() {}.getType();
321+
final Type inferFrom = Bar.class;
322+
323+
Map<TypeVariable<?>, MatchingUtils.TypeMapping> typeAssigns =
324+
new HashMap<>();
325+
MatchingUtils.inferTypeVariables(type, inferFrom, typeAssigns);
326+
327+
// We expect O = Any
328+
TypeVariable<?> typeVarO = (TypeVariable<?>) new Nil<O>() {}.getType();
329+
Map<TypeVariable<?>, MatchingUtils.TypeMapping> expected = new HashMap<>();
330+
expected.put(typeVarO, new TypeMapping(typeVarO, new Any(), true));
331+
332+
assertEquals(expected, typeAssigns);
333+
}
334+
335+
class Bar {
336+
337+
}
338+
339+
class TypedBar<E> extends Bar {
340+
E type;
341+
}
296342
}

0 commit comments

Comments
 (0)