Skip to content

inferTypeVariables: insert Anys in Map when applicable#22

Merged
hinerm merged 9 commits into
masterfrom
scijava/scijava-ops/inferTypeVariablesWithAny
Jun 9, 2021
Merged

inferTypeVariables: insert Anys in Map when applicable#22
hinerm merged 9 commits into
masterfrom
scijava/scijava-ops/inferTypeVariablesWithAny

Conversation

@gselzer
Copy link
Copy Markdown
Member

@gselzer gselzer commented Aug 21, 2020

Closes scijava/scijava#49

TODO:

  • Finish testing

    • It would be nice to write an Any.equals() for testing purposes, however we must decide the semantics. When should two Anys be considered equal? Are there cases when other Objects (that are not Anys) should be considered equal?
    • For which other Types can this scenario occur? Object is special in that Types.getExactSuperType will return null (not Object) for a call Types.getExactSuperType(i, Object.class) for any interface i (since Object is not a supertype of i).
  • Clean inferTypeVariables(ParameterizedType type, ...)

@gselzer
Copy link
Copy Markdown
Member Author

gselzer commented Aug 25, 2020

After a bit of testing, I realized these errors come from attempting to infer type variables from:

  • Object
  • Classes and Interfaces that have no type parameters (this doesn't come up often in scijava-ops, but could happen when trying to infer a Img<O> from an Interval)
  • Raw Classes

These situations are all solved (well, the tests will fail until we solve the Any equals semantics)

@gselzer gselzer force-pushed the scijava/scijava-ops/inferTypeVariablesWithAny branch from 7449576 to d90442c Compare August 26, 2020 18:12
@gselzer gselzer marked this pull request as ready for review August 26, 2020 18:27
gselzer added 9 commits May 18, 2021 14:02
This situation comes up often when calling something along the lines of:

  ops.op("name").inType(Double.class).apply()

which creates an OpRef looking for a

  Function<Double, Object>

Suppose the Op we wanted to match was a

  Function<I, Iterable<O>>

  (Disregard how bad of a Function typing this is)

MatchingUtils.inferTypeVariables() did not put the O in its
typeMappings, which throws IAEs later on. This is specifically because
Object IS NOT a superType of Iterable (and therefore I do not think this
problem can occur with any type other than Object??).

This problem is solved by adding Anys whenever an Object is found.
This is a better option going forward, and we now do not have to mess
with the Eclipse formatter.
This test focuses on the assignment

Function<Double, Object> <- Function<T, List<T>>

where T extends Number

This is ONLY safely assignable, since this is not compile-time safe.
This test should be differentiated from the no output tests within
OpBuilderTest in that tests within this class are more complex. The
no-output tests within OpBuilderTest merely ensure that a) the methods
continue to exist and b) that basic functionality is available. This
class tests more complicated functionality contingent on no output
(which is currently limited to ensuring ParameterizedType outputs do not
 cause error when no output is specified)
Interfaces and Classes (without type variables) will face a similar problem as
Objects (which was earlier solved)
@gselzer gselzer force-pushed the scijava/scijava-ops/inferTypeVariablesWithAny branch from d90442c to dee9d1b Compare May 18, 2021 19:02
@gselzer
Copy link
Copy Markdown
Member Author

gselzer commented May 18, 2021

@ctrueden I just rebased this over master, think it is ready to merge

@hinerm hinerm merged commit 5247a0f into master Jun 9, 2021
@ctrueden ctrueden deleted the scijava/scijava-ops/inferTypeVariablesWithAny branch November 20, 2021 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

Improve Handling of IAEs in DefaultOpEnvironment.adaptOp

3 participants