fix: handle Kotlin 1.9+ $ENTRIES pattern in enum restoration#2814
Merged
skylot merged 2 commits intoskylot:masterfrom Mar 7, 2026
Merged
fix: handle Kotlin 1.9+ $ENTRIES pattern in enum restoration#2814skylot merged 2 commits intoskylot:masterfrom
skylot merged 2 commits intoskylot:masterfrom
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
The smali test file was generated from the following Kotlin source using package enums
enum class TestEnumKotlinEntries {
ALPHA,
BETA,
GAMMA
}Compiled with |
Owner
|
Thanks, code looks good and succesfully restores enum, but it keeps public enum TestEnumKotlinEntries {
ALPHA,
BETA,
GAMMA;
public static EnumEntries<TestEnumKotlinEntries> getEntries() {
return $ENTRIES;
}
}And it is better to generate compilable code, so I fix this PR to keep public enum TestEnumKotlinEntries {
ALPHA,
BETA,
GAMMA;
private static final /* synthetic */ EnumEntries $ENTRIES = EnumEntriesKt.enumEntries(values());
public static EnumEntries<TestEnumKotlinEntries> getEntries() {
return $ENTRIES;
}
} |
skylot
approved these changes
Mar 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
NOTE: This is what one may call "AI slop". Feel free to close this PR if it's not up to your quality standards or even if you just aren't interested in reviewing it. I use these changes downstream on an APK and thought I might as well make a PR offering to upstream them, as your CONTRIBUTING.md doesn't say anything discouraging this.
Kotlin 1.9+ compiles enums with an additional
$ENTRIESfield initialized from the$VALUESarray viaEnumEntriesKt.enumEntries(). EnumVisitor did not recognize this pattern, causing enum restoration to fail for most Kotlin 1.9+ enum classes.The fix handles three cases:
$ENTRIESSPUT, handling both the wrapped case (INVOKE inlined into SPUT by CodeShrinkVisitor) and the standalone caseInsnArg.unwrap()returns null for RegisterArg, causing NPE when checking FILLED_NEW_ARRAY external usesIncludes a smali test compiled from a real Kotlin 2.3 enum.
Tested on Tumblr v43.4.0.107 (
com.tumblr, 22,124 classes):