feat(jdk-codemodel): resolve Symbol.EnhancedForVariable, Symbol.CatchParameter, and Symbol.PatternBinding#118
Merged
Merged
Conversation
…Parameter, and Symbol.PatternBinding
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.
Symbol.LocalVariablealready resolved back to its declaringLocalVariableDeclaration, but three other locally-scoped variable-declaring constructs had no equivalent path: enhanced-for loop variables, catch-clause exception parameters, andinstanceof/switch pattern bindings. Identifiers referencing them either fell back to a type-onlySymbol.LocalVariablewith a permanently-empty declaration, or in the catch/pattern-binding cases got noSymboltrait at all.Added three new sealed
Symbolvariants —Symbol.EnhancedForVariable,Symbol.CatchParameter, andSymbol.PatternBinding— each carrying a directOptionalreference to its declaring construct (EnhancedFor,CatchClause,InstanceOf), matching the existingSymbol.LocalVariableshape.JdkExpressionConverter.resolveSymbolnow handles theEXCEPTION_PARAMETERandBINDING_VARIABLEelement kinds, and distinguishes enhanced-for locals from plain locals since javac reports both underLOCAL_VARIABLE. A direct object reference (rather thanSymbol.Field's live/CodeModel-resolved style) is correct here because none of these constructs can outlive arescan()independently of the identifiers referencing them —rescan()evicts and rebuilds a wholeTypeDescriptor, and hence a whole method body, atomically.Wiring this up surfaced a real construction-order bug: unlike
LocalVariableDeclaration, whose scope is sibling statements converted after it returns,EnhancedForandCatchClauseeach contain their own body as a child, which is the only place their variable can ever be referenced. The body was being converted as a constructor argument before the wrapping node existed, so there was nothing yet to register when resolving identifiers inside it. Fixed by giving both classes a package-visible two-phase construction path —ofPending(...)followed by a call-oncecompleteBody(...)— so the declaring construct's element can be registered before its body is converted. The node stays fully immutable from any external caller's perspective.InstanceOfneeded no such change, since a pattern binding's scope is the enclosingif/switch-case body, a sibling node converted afterward.