[java] Fix #6146: ClassCastException in TypeTestUtil #6156
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#6146 (comment)
(thanks for the test case @zbynek)
In this example, the problem was that
filteris applicableTwith an inference variable'a. We set the type of the lambda to bePredicate<? super 'a>, which means the type of its parameterinputis'a.T = (*unknown*)andT = Bar(from the argumentunknown()and the context typeIterable<Bar>respectively). Those are considered incompatible so we fail.inputso the inference variable stay in the treeThis fix has three parts
Predicate<(*error*)>and typeinputas(*error*), removing the'afrom AST nodes. This was the root problem really.T = (* unknown *)andT = Barto be compatible. This improves type inference when types are missing from the classpath, and will allow the invocation in this example not to fail. To be complete,{T = (*unknown*), T = Bar}will solve toBar, and{T = (*error*), T = Bar}will solve to(*error*), that is, the error type is contagious.Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)