Repository navigation
Resolve Static Final Constants in Refinement Aliases - #423
Merged
Merged
Conversation
Constants like ImageWriteParam.MODE_EXPLICIT were resolved in refinements and state refinements, but not inside @RefinementAlias bodies, which are parsed through a separate path. Resolve them against the imports of the class declaring the alias, and report unresolvable ones at the alias. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Static final constants (e.g.
ImageWriteParam.MODE_EXPLICIT) can be used in@Refinementand@StateRefinementpredicates, but not inside a@RefinementAliasbody. Alias definitions are parsed throughRefinementsParser.parseAliasDefinition, which skips the constant resolution done in thePredicateconstructor, so the constant stayed an unresolved name.Before, this failed with an error reported at the wrong annotation (the
@StateRefinement, even when that line no longer mentioned the constant):Changes
TypeChecker#handleAliasnow resolves constants in the parsed alias body, using the class that declares the alias as context, so its imports apply.Predicate#resolveStaticFinalConstantsgets a public overload that takes an error position. For aliases, an unresolvable constant is reported at the@RefinementAliasannotation:Enum#clonekeeps the resolved literal, expanding the alias at each use site keeps the resolved values.Tests
CorrectStaticFinalInAlias: alias withImageWriteParamconstants andByte.MAX_VALUE(implicitjava.lang)ErrorStaticFinalInAlias: value outside the alias rangeErrorStaticFinalInAliasMissingImport: missing import, error at the aliasclasses/alias_static_final_state_correct: alias plus constants in a@StateRefinementon external refinements (the original case)mvn test: 496 tests, 0 failures.🤖 Generated with Claude Code