[kotlin] K2 J2K: Avoid Using Any Type When Stricter Type is Known #2812
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.
This PR tries to infer the true type of any
JKNewExpression
with anAny
type argument. Meta has had many cases of types being set toAny?
when that is clearly incorrect based on the information provided by that particular expression.In
TypeMappingConversion
, we now run an extra step if the type argument isAny
and the number of parameters matches the number of type arguments (since if they don't match, it's impossible to infer anything further). In that case, we:Any
or if the corresponding parameter type is null/unknownAny
if there are multiple type arguments required. Otherwise, it's safer to just leave it out.This will prevent errors such as the one in
plugins/kotlin/j2k/shared/tests/testData/newJ2k/issues/kt-1048.kt
and previously innoUnnecessaryAny.kt
where the inferred type is clear butAny
was used anyways