|
14 | 14 | import java.util.function.Function; |
15 | 15 |
|
16 | 16 | import org.junit.Test; |
17 | | -import org.scijava.ops.function.Producer; |
18 | 17 | import org.scijava.ops.matcher.MatchingUtils.TypeInferenceException; |
19 | 18 | import org.scijava.ops.matcher.MatchingUtils.TypeMapping; |
20 | 19 | import org.scijava.ops.matcher.MatchingUtilsTest.StrangeThing; |
@@ -351,11 +350,56 @@ public <O extends Number> void testInferOToAnyWithRawType() |
351 | 350 | assertEquals(expected, typeAssigns); |
352 | 351 | } |
353 | 352 |
|
| 353 | + @Test |
| 354 | + public <O extends Number, I extends O> void testInferTypeVarExtendingTypeVar() { |
| 355 | + final Type type = new Nil<I>() {}.getType(); |
| 356 | + final Type inferFrom = Double.class; |
| 357 | + |
| 358 | + Map<TypeVariable<?>, MatchingUtils.TypeMapping> typeAssigns = |
| 359 | + new HashMap<>(); |
| 360 | + MatchingUtils.inferTypeVariables(type, inferFrom, typeAssigns); |
| 361 | + |
| 362 | + // We expect I= Double, O = Double |
| 363 | + Map<TypeVariable<?>, MatchingUtils.TypeMapping> expected = new HashMap<>(); |
| 364 | + TypeVariable<?> typeVarI = (TypeVariable<?>) new Nil<I>() {}.getType(); |
| 365 | + expected.put(typeVarI, new TypeMapping(typeVarI, Double.class, true)); |
| 366 | + TypeVariable<?> typeVarO = (TypeVariable<?>) new Nil<O>() {}.getType(); |
| 367 | + expected.put(typeVarO, new TypeMapping(typeVarO, Double.class, true)); |
| 368 | + |
| 369 | + assertEquals(expected, typeAssigns); |
| 370 | + } |
| 371 | + |
| 372 | + @Test |
| 373 | + public <O extends RecursiveThing<O>> void testInferRecursiveTypeVar() { |
| 374 | + final Type type = new Nil<O>() {}.getType(); |
| 375 | + final Type inferFrom = FooThing.class; |
| 376 | + |
| 377 | + Map<TypeVariable<?>, MatchingUtils.TypeMapping> typeAssigns = |
| 378 | + new HashMap<>(); |
| 379 | + MatchingUtils.inferTypeVariables(type, inferFrom, typeAssigns); |
| 380 | + |
| 381 | + // We expect O = FooThing |
| 382 | + TypeVariable<?> typeVarO = (TypeVariable<?>) new Nil<O>() {}.getType(); |
| 383 | + Map<TypeVariable<?>, MatchingUtils.TypeMapping> expected = new HashMap<>(); |
| 384 | + expected.put(typeVarO, new TypeMapping(typeVarO, FooThing.class, false)); |
| 385 | + |
| 386 | + assertEquals(expected, typeAssigns); |
| 387 | + } |
| 388 | + |
354 | 389 | class Bar { |
355 | 390 |
|
356 | 391 | } |
357 | 392 |
|
358 | 393 | class TypedBar<E> extends Bar { |
359 | 394 | E type; |
360 | 395 | } |
| 396 | + |
| 397 | + static abstract class RecursiveThing<T extends RecursiveThing<T>> { |
| 398 | + |
| 399 | + } |
| 400 | + |
| 401 | + static class FooThing extends RecursiveThing<FooThing> { |
| 402 | + |
| 403 | + } |
| 404 | + |
361 | 405 | } |
0 commit comments