Skip to content

Kotlin: minimize the usage of 'JvmSuppressWildcards'#1793

Merged
pwrobeldev merged 7 commits intomasterfrom
pwrobeldev/kotlin-minimize-the-usage-of-jvm-suppress-wildcards
Jan 26, 2026
Merged

Kotlin: minimize the usage of 'JvmSuppressWildcards'#1793
pwrobeldev merged 7 commits intomasterfrom
pwrobeldev/kotlin-minimize-the-usage-of-jvm-suppress-wildcards

Conversation

@pwrobeldev
Copy link
Contributor

@pwrobeldev pwrobeldev commented Jan 22, 2026

---------- Motivation ----------
The annotation mentioned in the title of the commit was used
for parameter types of collections (List, Map, Set) to avoid
interoperability problems when the generated code is accessed
from Java.

The problematic case is checked in KotlinInteropTest.java.

However, it turns out that the mentioned annotation needs to be
only used for enums and open types, because if the type is final
then wildcard is not generated.

---------- Solution ----------
KotlinNameResolver class is adjusted to generate the annotation for
parameter type of collection only when it is enum or the type is open.

Smoke tests are adjusted to showcase that this change minimizes the
usage of 'JvmSuppressWildcards' annotation.

The functional test called 'KotlinInteropTest.java' passes without problems after the change.

The annotation was used for each parameter type
of collections. This was not needed. The annotation
only needs to be used for open types which are:
 - open classes
 - interfaces
 - lambdas (generated as fun interfaces in Kotlin)

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Hsilgos
Hsilgos previously approved these changes Jan 22, 2026
Add test cases that pass.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
The new test experiences compilation error because of missing
'JvmSuppressWildcards'.

```
gluecodium/functional-tests/functional/android/src/test/java/com/here/android/test/KotlinInteropTest.java:82:
error: incompatible types: List<CAP#1> cannot be converted to List<SomeDummyEnum>
    assertEquals(0, someJavaFunctionThatTakesListOfEnums(someStruct.enumList));
                                                                   ^
  where CAP#1 is a fresh type-variable:
    CAP#1 extends SomeDummyEnum from capture of ? extends SomeDummyEnum
```

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
@pwrobeldev pwrobeldev merged commit 4ebce39 into master Jan 26, 2026
33 of 35 checks passed
@pwrobeldev pwrobeldev deleted the pwrobeldev/kotlin-minimize-the-usage-of-jvm-suppress-wildcards branch January 26, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants