[generator] Handle Kotlin metadata when only one metadata exists for multiple Java methods. #1009
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.
Fixes: #984
There exists a scenario in Kotlin where an instance method and an extension method can have the same Kotlin parameter signature:
This results in 2 different Java methods:
In this case, Kotlin only generates 1 metadata entry:
Today we find that the
JvmSignature
of([BB)Z
matches thestatic
contains-7apg3OU
and apply the metadata to that method.However, if we ignore the
JvmSignature
and match on theValueParameters
, then this metadata matches the instancecontains-7apg3OU
method.We surmise that this is intentional on Kotlin's part, in order to save bytes by omitting the second metadata entry, and that we should apply this metadata to both Java methods.
Note: the "hash" appended to the Java method name (eg:
7apg3OU
) is a short hash of the Kotlin method parameter types.The Fix
Today we loop through the Kotlin metadata, find the single Java method that matches, and apply the metadata to that match.
In order to support a one-to-many metadata relationship, we need to do the opposite.
We now loop through the Java methods and find the best matching Kotlin metadata entry, if any. (Often there is none.)
In this way, each Java method can consume a matching Kotlin metadata entry, even if another Java method has already matched it.
Results Against kotlin-stdlib 1.6
This fixes the 4
contains
methods forUIntArray
,UByteArray
,ULongArray
, andUShortArray
.