fix(core): restore enum initialized with external SGET field (#2618)#2918
Open
gaurav0107 wants to merge 1 commit into
Open
fix(core): restore enum initialized with external SGET field (#2618)#2918gaurav0107 wants to merge 1 commit into
gaurav0107 wants to merge 1 commit into
Conversation
…2618) An enum constant constructor can take an argument whose value is a static field read (SGET) of an external constant, e.g. a constant of another enum that is reused across several enum fields. R8 keeps such a reused value in a register instead of inlining it, so it reaches EnumVisitor as a register argument. inlineExternalRegs only handled arguments referencing another constant of the same enum and aborted restoration with "Init of enum field '...' uses external variables" for the external SGET case, emitting the class without the enum modifier. Inline the external SGET into the enum field initializer, mirroring how same-enum references are already inlined, so the enum is restored correctly. Fixes skylot#2618
gaurav0107
marked this pull request as ready for review
July 15, 2026 23:27
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.
Problem
Fixes #2618. When a Dalvik enum's constant constructors take an argument whose SSA value is a static-field read (
SGET) of an external constant — typically a constant of another enum, reused across several constants so R8 keeps it in a register instead of inlining it —EnumVisitorfails to restore the enum:The class is then emitted as a plain
classwith theenummodifier and super class stripped.Fix
inlineExternalRegsalready inlines a constructor argument that references another constant of the same enum. This extends it: when the argument's SSA value is instead assigned by an externalSGET, inline a copy of thatSGETinto the enum-field initializer. Existing behaviour is unchanged — the new branch is only reached where the old code returnednull(and threw).Test
Adds
TestEnumExternalSget(multi-fileSmaliTest, reduced from the reporter's sample): an enum whose constants pass reusedExtEnum.*values to the constructor. Before the fix the class is emitted asclasswith the enum-restore-failure warning; after, it is restored asenum TestEnumExternalSgetwithA(ExtEnum.FIRST),B(ExtEnum.FIRST),C(ExtEnum.SECOND).Verified locally: the full
jadx.tests.integration.enums.*package is green (33 tests), the whole:jadx-core:testsuite shows no new failures versus master, and:jadx-core:spotlessCheckpasses.