[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 4 commits intogoogle:masterfrom
Conversation
|
@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 |
|
Doesn't build? |
|
Okay, I will look at the issue. |
- 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
b11ff29 to
3cdd15f
Compare
|
Can you please run the work now? |
|
Looks like you've put back the wildcards. Can you summarize what this PR changes? I ask because it's my impression that the PR's goal is to remove the wildcard. Now that it's restored, what's changed after all? (sorry the github diff confuses me a little) |
Summary
Updates
MoreCollectorsTestto avoid Java type-inference failures aroundallMin()/allMax()when usingnaturalOrder().Problem
On this branch state, 6 tests in
MoreCollectorsTestfail to compile with unresolved type inference errors at calls such as:allMax(naturalOrder(), toImmutableList())allMin(naturalOrder(), toImmutableSet())allMax(naturalOrder(), onlyElement())allMin(naturalOrder(), onlyElement())Fix
Test-only update in
mug/src/test/java/com/google/mu/util/stream/MoreCollectorsTest.java:naturalOrder()(no explicitComparator.<Integer>type witness)onlyElement()call sites to provide explicit mapping lambdas (onlyElement(i -> i))No production code changes are included in the final PR diff.
Tests
Validated locally with:
mvn -pl mug -Dtest=MoreCollectorsTest testmvn -pl mug clean test -Dtest=MoreCollectorsTestBoth pass.