Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out $EntriesMappings class for Kotlin's 1.9 feature 'Enum entries' #144

Merged
merged 4 commits into from Aug 15, 2023

Conversation

fzhinkin
Copy link
Collaborator

Kotlin compiler generates synthetic class holding EnumEntries starting from 1.9. This change filters out such classes from the API dump.

Closes #141

…ies'

Kotlin compiler generates synthetic class holding EnumEntries starting from 1.9.
This change filters out such classes from the API dump.
@fzhinkin
Copy link
Collaborator Author

While the change is trivial, I don't see a way to test it easily.
I verified the behavior in a separate project, but I don't see how to pack it into a unit test that could be merged along with the change.
Maybe someone has good ideas regarding it?

@qwwdfsad
Copy link
Member

qwwdfsad commented Jun 14, 2023

Updating Kotlin to 1.9.0-Beta will do the trick.
We do ensure compatibility via apiVersion/languageVersion and later even the concern with transitive dependencies will cease to exist

Changed config to make testing of Enum.entries possible.
Enum.entries require stdlib >= 1.8.20.
Exclusion of stdlib artifacts is only required when Gradle's Kotlin version is higher than the project's one.
@fzhinkin
Copy link
Collaborator Author

fzhinkin commented Jul 4, 2023

Updated to 1.8.20 instead, also removed exclusion of stdlib artifacts (it does nothing when the version of Kotlin from Gradle's classpath is lower, which is the case right now).

@fzhinkin
Copy link
Collaborator Author

ping

@fzhinkin fzhinkin requested a review from qwwdfsad August 10, 2023 11:40
@@ -40,6 +41,7 @@ fun ClassNode.isLocal() = outerMethod != null
fun ClassNode.isInner() = innerClassNode != null
fun ClassNode.isWhenMappings() = isSynthetic(access) && name.endsWith("\$WhenMappings")
fun ClassNode.isSyntheticAnnotationClass() = isSynthetic(access) && name.contains("\$annotationImpl\$")
fun ClassNode.isEnumEntriesMappings() = isSynthetic(access) && name.endsWith("\$EntriesMappings")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are currently no tests that check this behaviour.

You'll need when over old Kotlin enum (unlikely it's easy to get one in the robust manner) or any Java one in the code to force $EntriesMapping appearance

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing to this! Seems like IDE cached something wrong, so when I validated the test without ClassNode.isEnumEntriesMappings EntriesMapping was there despite the fact that Enum is a "new" enum.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries.

There is something suspicious happening:

  1. IDE highlights EnumClass.entries as available only since API version 1.8 (red code, [UNSUPPORTED_FEATURE]) even though you clearly set it up
  2. For clean builds, everything works as expected
  3. For incremental builds (run all tests, change something in entries.kt), mappings start being generated even though entries member is present

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll proceed with the issue further

@fzhinkin fzhinkin requested a review from qwwdfsad August 15, 2023 08:14
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.

Filter out $EntriesMappings class for Kotlin's 1.9 feature 'Enum entries'
2 participants