diff --git a/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/ConversionMatchingRoutine.java b/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/ConversionMatchingRoutine.java index fc020e593..68c468441 100644 --- a/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/ConversionMatchingRoutine.java +++ b/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/ConversionMatchingRoutine.java @@ -77,17 +77,11 @@ public OpCandidate findMatch(MatchingConditions conditions, OpMatcher matcher, .hints())) { Conversions.tryConvert(env, info, request).ifPresent(converted -> { - Map, Type> map = new HashMap<>(); - GenericAssignability.inferTypeVariables( // - new Type[] { converted.opType() }, // - new Type[] { request.getType() }, // - map // - ); candidates.add(new OpCandidate( // env, // request, // converted, // - map // + converted.typeVarAssigns() // )); }); } diff --git a/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/Conversions.java b/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/Conversions.java index a9cb76d4a..652c31bb2 100644 --- a/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/Conversions.java +++ b/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/Conversions.java @@ -34,6 +34,7 @@ import org.scijava.function.Mutable; import org.scijava.ops.api.*; import org.scijava.ops.engine.BaseOpHints; +import org.scijava.types.Any; import org.scijava.types.Nil; import org.scijava.types.Types; import org.scijava.types.inference.FunctionalInterfaces; @@ -136,7 +137,7 @@ private static ConvertedOpInfo convert(OpEnvironment env, OpInfo info, return opt.get(); } // Attempt 2: Computer with identity mutable output - opt = postprocessIdentity(info, request, preConverters, env); + opt = postprocessIdentity(info, request, preConverters, vars, env); if (opt.isPresent()) { return opt.get(); } @@ -209,7 +210,8 @@ private static Optional postprocessFunction(OpInfo info, postConverter, // request.getOutType(), // null, // - env // + env, // + vars // )); } @@ -231,7 +233,7 @@ private static Optional postprocessFunction(OpInfo info, */ private static Optional postprocessIdentity(OpInfo info, OpRequest request, List>> preConverters, - OpEnvironment env) + Map, Type> vars, OpEnvironment env) { // This procedure only applies to Ops with mutable outputs int ioIndex = mutableIndexOf(request.getType()); @@ -252,7 +254,8 @@ private static Optional postprocessIdentity(OpInfo info, null, // request.getOutType(), // null, // - env // + env, // + vars // )); } return Optional.empty(); @@ -312,7 +315,8 @@ private static Optional postprocessConvertAndCopy( postConverter, // request.getOutType(), // copyOp, // - env // + env, // + vars // )); } catch (OpMatchingException e) { @@ -375,7 +379,8 @@ private static Optional postprocessCopy(OpInfo info, postConverter, // request.getOutType(), // copyOp, // - env // + env, // + vars // )); } catch (OpMatchingException e) { @@ -443,13 +448,17 @@ private static void resolveTypes(Type source, Type dest, */ private static Nil wildcardVacuousTypeVars(final Type t) { Type[] typeParams = Types.typeParamsAgainstClass(t, Types.raw(t)); + if (t instanceof TypeVariable) { + TypeVariable tv = (TypeVariable) t; + return Nil.of(new Any(tv.getBounds())); + } var vars = new HashMap, Type>(); for (Type typeParam : typeParams) { if (typeParam instanceof TypeVariable) { // Get the type variable TypeVariable from = (TypeVariable) typeParam; // Create a wildcard type with the type variable bounds - Type to = Types.wildcard(from.getBounds(), null); + Type to = new Any(from.getBounds()); vars.put(from, to); } } diff --git a/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/ConvertedOpInfo.java b/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/ConvertedOpInfo.java index 96efa3b11..1d08996ae 100644 --- a/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/ConvertedOpInfo.java +++ b/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/ConvertedOpInfo.java @@ -94,6 +94,7 @@ public class ConvertedOpInfo implements OpInfo { private final OpInfo info; private final OpEnvironment env; + private final Map, Type> typeVarAssigns; final List>> preconverters; final List inTypes; final RichOp> postconverter; @@ -116,7 +117,9 @@ public ConvertedOpInfo(OpInfo info, Arrays.asList(inTypes(info.inputTypes(), preconverters)), // postconverter, // outType(info.outputType(), postconverter), copyOp, // - env // + env, // + // TODO: Fix? + Collections.emptyMap() // ); } @@ -138,7 +141,8 @@ public ConvertedOpInfo( // RichOp> postconverter, // Type reqOutput, // final RichOp> copyOp, // - OpEnvironment env // + OpEnvironment env, // + Map, Type> typeVarAssigns // ) { this.info = info; this.opType = mapAnys(opType, info); @@ -153,6 +157,7 @@ public ConvertedOpInfo( // BaseOpHints.Conversion.FORBIDDEN, // "converted" // ); + this.typeVarAssigns = typeVarAssigns; } /** @@ -943,4 +948,7 @@ private static String fMethodPreprocessing( return sb.toString(); } + public Map, Type> typeVarAssigns() { + return this.typeVarAssigns; + } } diff --git a/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/IdentityCollection.java b/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/IdentityCollection.java index 123074aa6..d1d97819c 100644 --- a/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/IdentityCollection.java +++ b/scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/convert/IdentityCollection.java @@ -45,7 +45,7 @@ * @author Gabriel Selzer * @param */ -public class IdentityCollection implements OpCollection { +public class IdentityCollection implements OpCollection { /** * @input t the object to be converted @@ -55,7 +55,7 @@ public class IdentityCollection implements OpCollection { @OpHints(hints = { Conversion.FORBIDDEN, BaseOpHints.DependencyMatching.FORBIDDEN }) @OpField(names = "engine.convert, engine.identity", priority = Priority.FIRST) - public final Function identity = (t) -> t; + public final Function identity = (t) -> t; /** * @mutable t the object to be "mutated"