Skip to content

Add constantValue to JavaType.Variable for compile-time constants#7070

Draft
knutwannheden wants to merge 1 commit intomainfrom
oddly-moose
Draft

Add constantValue to JavaType.Variable for compile-time constants#7070
knutwannheden wants to merge 1 commit intomainfrom
oddly-moose

Conversation

@knutwannheden
Copy link
Contributor

Summary

  • Adds a @Nullable Object constantValue field to JavaType.Variable to store compile-time constant values (primitives and String)
  • Populates the value from VarSymbol.getConstValue() in all Java parser variants (8, 11, 17, 21, 25)
  • Populates from Field.get(null) in the reflection type mapping path
  • Populates from Roslyn's IFieldSymbol.ConstantValue in the C# type mapping
  • Updates RPC sender/receiver across all languages (Java, Python, TypeScript, C#)
  • Passes null for 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 comparing Constants.TIMEOUT (with value 30) against a literal 30 should be recognized as semantically equal.

Scope

Only JVM ConstantValue-eligible types: boolean, byte, short, char, int, long, float, double, and String. 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-constants
  • constantValueFromClasspath — verifies Integer.MAX_VALUE is resolved via the TypeTable/classpath path
  • Full rewrite-java-17 test suite passes with no regressions
  • Cross-language RPC tests (Python, JS, C#) should be validated in CI

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).
@knutwannheden knutwannheden changed the title Add constantValue to JavaType.Variable for compile-time constants Add constantValue to JavaType.Variable for compile-time constants Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant