Skip to content

Commit b19db82

Browse files
committed
inferTypeVariables: map Anys for raw classes too
1 parent 755b080 commit b19db82

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎scijava/scijava-ops/src/main/java/org/scijava/ops/matcher/MatchingUtils.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ else if (superInferFrom instanceof Class) {
627627
" cannot be implicitly cast to " + mappedType +
628628
", thus it is impossible to infer type variables for " + inferFrom);
629629
}
630+
// for all remaining unmapped type vars, map to Any
631+
mapTypeVarsToAny(type, typeMappings);
630632
}
631633
// -- edge cases -> do our best -- //
632634
else if (superInferFrom == null) {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,25 @@ public <O extends Number> void testInferOToAnyWithClass()
332332
assertEquals(expected, typeAssigns);
333333
}
334334

335+
@Test
336+
public <O extends Number> void testInferOToAnyWithRawType()
337+
throws TypeInferenceException
338+
{
339+
final Type type = new Nil<TypedBar<O>>() {}.getType();
340+
final Type inferFrom = TypedBar.class;
341+
342+
Map<TypeVariable<?>, MatchingUtils.TypeMapping> typeAssigns =
343+
new HashMap<>();
344+
MatchingUtils.inferTypeVariables(type, inferFrom, typeAssigns);
345+
346+
// We expect O = Any
347+
TypeVariable<?> typeVarO = (TypeVariable<?>) new Nil<O>() {}.getType();
348+
Map<TypeVariable<?>, MatchingUtils.TypeMapping> expected = new HashMap<>();
349+
expected.put(typeVarO, new TypeMapping(typeVarO, new Any(), true));
350+
351+
assertEquals(expected, typeAssigns);
352+
}
353+
335354
class Bar {
336355

337356
}

0 commit comments

Comments
 (0)