Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Anys, not wildcards, for converter output types #139

Merged
merged 1 commit into from
Apr 1, 2024

Conversation

gselzer
Copy link
Member

@gselzer gselzer commented Mar 22, 2024

Wildcard types are problematic due to the restrictions on e.g. the number of bounds. Anys are more flexible in this regard, and better reflect our needs.

TODO:

  • Test changeset.

@gselzer gselzer added the bug Something isn't working label Mar 22, 2024
@gselzer gselzer self-assigned this Mar 22, 2024
@gselzer gselzer force-pushed the scijava-ops-engine/conversion-more-anys branch 3 times, most recently from 4733b4d to 340c806 Compare April 1, 2024 17:28
@gselzer gselzer force-pushed the scijava-ops-engine/conversion-more-anys branch from 340c806 to 6fe3990 Compare April 1, 2024 17:33
@gselzer gselzer marked this pull request as ready for review April 1, 2024 17:34
@gselzer gselzer merged commit 4493eee into main Apr 1, 2024
2 checks passed
@gselzer gselzer deleted the scijava-ops-engine/conversion-more-anys branch April 1, 2024 17:45
Copy link
Member

@ctrueden ctrueden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Very clean. I just have two tiny nitpicks, and one slightly less tiny nitpick. But nothing that should hold up a merge.

if (t instanceof TypeVariable<?>) {
TypeVariable<?> tv = (TypeVariable<?>) t;
return Nil.of(new Any(tv.getBounds()));
}
var vars = new HashMap<TypeVariable<?>, 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is no longer correct.

@@ -55,7 +55,7 @@ public class IdentityCollection<T, U extends T> implements OpCollection {
@OpHints(hints = { Conversion.FORBIDDEN,
BaseOpHints.DependencyMatching.FORBIDDEN })
@OpField(names = "engine.convert, engine.identity", priority = Priority.FIRST)
public final Function<U, T> identity = (t) -> t;
public final Function<T, T> identity = (t) -> t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parens are unnecessary; you can just write t -> t.

* Op.
* </p>
*/
@OpMethod(names = "test.boundsConversion", type = BiFunction.class)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once again I got confused by the name of this op. It's weird to me that we have test ops named after the functionality being tested rather than named for what they do like normal ops. In this case, the op test.boundsConversion is a static method named foo (which I find unhelpful in understanding) and it returns the max of two objects. So why not name it "max" instead? Especially since the functionality being tested here, multiple type bounds, is also a sort of comparison, which was the source of my momentary confusion: "What does x > y ? x : y have to do with multiple bounds?" I thought, "It's just one bound..."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

2 participants