[BUG] Fix allMin/allMax test compilation errors with Comparator.naturalOrder()#108
[BUG] Fix allMin/allMax test compilation errors with Comparator.naturalOrder()#108akgitrepos wants to merge 3 commits intogoogle:masterfrom
Conversation
- Changed downstream collector type from Collector<? super T, ?, R> to Collector<T, ?, R> to improve type inference with Comparator.naturalOrder() - Added explicit type witnesses in tests: Comparator.<Integer>naturalOrder() and onlyElement(identity()) to help Java's type inference This fixes 6 test compilation errors: - testAllMax_empty - testAllMax_toOnlyElement - testAllMax_multiple - testAllMin_empty - testAllMin_toOnlyElement - testAllMin_multiple
|
@fluentfuture Hi, I have fixed test compilation issues on MoreCollectorsTest.java. Would appreciate a review. Thanks! |
|
Changing the wildcard could be a breaking change. What javac version are you using when getting this error? I wonder if we could tweak the tests instead to fix compilation. |
|
@fluentfuture I am using 20.0.2 version. I did run all the project test as well to ensure no regression. If you want I can try to tweak the test case as fix. |
|
Yeah. Looking closely, the wildcard is probably redundant anyways. The build for this PR seems to be failing though? |
|
@fluentfuture I see the issue. There were total of 6 test failing. Commit d4e10eb only has 2 test case update. I have updated the other 4 test case. Could you please re-run the workflow? |
|
@fluentfuture Any additional action on this? |
|
I left comment in the PR. Can you see it? Basically I don't think we want to force the users to have to add explicit types like Can you make it work without the |
|
@fluentfuture Updated the tests so they work without explicit type witnesses like |
Summary
Fixes 6 test compilation errors in
MoreCollectorsTest.javathat prevent tests from compiling when usingComparator.naturalOrder()with theallMin/allMaxcollector methods.Problem
Tests like
testAllMax_empty,testAllMax_toOnlyElement, etc. fail with:Java's type inference fails when combining:
Comparator.naturalOrder()- returnsComparator<Comparable<? super T>>toImmutableList()- returnsCollector<Object, ?, ImmutableList<Object>>The wildcards
? super Tin the method signature prevent Java from correctly inferringT.Solution
1. Method signature change (
MoreCollectors.java)Changed downstream collector type from
Collector<? super T, ?, R>toCollector<T, ?, R>:2. Test fixes (
MoreCollectorsTest.java)Added explicit type witnesses to ensure robust type inference:
Comparator.<Integer>naturalOrder()onlyElement(identity())Files Changed
mug/src/main/java/com/google/mu/util/stream/MoreCollectors.java(2 lines)mug/src/test/java/com/google/mu/util/stream/MoreCollectorsTest.java(2 lines)Testing