Add constantValue to JavaType.Variable for compile-time constants#7070
Draft
knutwannheden wants to merge 1 commit intomainfrom
Draft
Add constantValue to JavaType.Variable for compile-time constants#7070knutwannheden wants to merge 1 commit intomainfrom
constantValue to JavaType.Variable for compile-time constants#7070knutwannheden wants to merge 1 commit intomainfrom
Conversation
Store the compile-time constant value (primitives and String) on JavaType.Variable, sourced from javac's VarSymbol.getConstValue(), reflection's Field.get(null), and Roslyn's IFieldSymbol.ConstantValue. This enriches the type model to support future constant propagation in recipes like SemanticallyEqual. Updates the Variable type definition, type attribution, and RPC sender/receiver across all languages (Java, Python, TypeScript, C#, Kotlin, Groovy).
f194908 to
625f2d2
Compare
constantValue to JavaType.Variable for compile-time constants
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.
Summary
@Nullable Object constantValuefield toJavaType.Variableto store compile-time constant values (primitives andString)VarSymbol.getConstValue()in all Java parser variants (8, 11, 17, 21, 25)Field.get(null)in the reflection type mapping pathIFieldSymbol.ConstantValuein the C# type mappingnullfor Groovy and Kotlin type mappings (no constant extraction yet)Motivation
This enriches the type model to enable future constant propagation in recipes like
SemanticallyEqual, where comparingConstants.TIMEOUT(with value30) against a literal30should be recognized as semantically equal.Scope
Only JVM
ConstantValue-eligible types:boolean,byte,short,char,int,long,float,double, andString. Does not cover enum constants, class literals, or non-compile-time-constant expressions.Test plan
constantValueOnStaticFinalFields— verifies constant values from source parsing (int, long, String, boolean, double) and null for non-constantsconstantValueFromClasspath— verifiesInteger.MAX_VALUEis resolved via the TypeTable/classpath pathrewrite-java-17test suite passes with no regressions