Skip to content

fix(jdk-codemodel): defer method/field body conversion to a second pass so forward type references resolve#107

Merged
deer merged 1 commit into
mainfrom
two_pass_resolution
Jul 6, 2026
Merged

fix(jdk-codemodel): defer method/field body conversion to a second pass so forward type references resolve#107
deer merged 1 commit into
mainfrom
two_pass_resolution

Conversation

@deer

@deer deer commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

JdkInitializer used to register a type's descriptor and convert its method bodies, constructor bodies, field initializers, and static/instance initializer blocks in the same single pass over compilation units, in source-list order, via processMembers/processField/processConstructor/processMethod. This meant that if a source file processed earlier in the list called into a type processed later, the call would silently fail to resolve since JdkExpressionConverter's resolveField/resolveParameter/resolveMethod return Optional.empty() when the target type's descriptor isn't registered yet, with no diagnostic.

The fix collects each type's body/initializer work into a bodyTasks list during the registration walk, then defers actual conversion via deferredConversions until every compilation unit's type descriptors have been registered, re-establishing exprConverter's type context and enclosing type for each deferred task since that context is mutated while scanning subsequent classes.

Added TwoPassResolutionTests to reproduce the bug directly at the codemodel level with in-memory sources, asserting that a caller's call to a callee resolves to a ResolvedMethod trait regardless of which order the two types are passed to JdkInitializer.

@deer deer merged commit 6240a8a into main Jul 6, 2026
1 check passed
@deer deer deleted the two_pass_resolution branch July 6, 2026 13:15
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.

1 participant