Skip to content

Support for class Constants #207

Open
CatarinaGamboa wants to merge 6 commits intomainfrom
finalstatics
Open

Support for class Constants #207
CatarinaGamboa wants to merge 6 commits intomainfrom
finalstatics

Conversation

@CatarinaGamboa
Copy link
Copy Markdown
Collaborator

@CatarinaGamboa CatarinaGamboa commented May 4, 2026

We did not support using static final fields from classes in predicates or using the values in Java code.
For example, both these cases would not have been possible before, and now are acceptable

    static void clampInt(@Refinement("_ >= Integer.MIN_VALUE && _ <= Integer.MAX_VALUE") int x) {
    }

    public static void main(String[] args) {
        clampInt(0);
        clampInt(Integer.MAX_VALUE);
    }
  • Resolution follows Java scoping rules: fully-qualified name → compilation-unit imports (single + on-demand) → implicit java.lang, with reflection as the source-of-truth. User-defined enums/classes are left untouched for the existing SMT path.
  • Based on reflection, find the declaration and get the value assigned to it, and add it as a value.

if (!(exp instanceof GroupExpression)) {
exp = new GroupExpression(exp);
}
exp = resolveStaticFinalConstants(exp, element);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to call this all the time?

it will just see if there are enums to resolve in a small expression, if there are no enums it doesnt do anything else, so its fine

@CatarinaGamboa
Copy link
Copy Markdown
Collaborator Author

@rcosta358 I'm not sure how this affects error messages as it will appear directly with the value in the SMT, but there is no link between the var and its value so we might need a followup pr to handle that

@rcosta358
Copy link
Copy Markdown
Collaborator

Can't we treat those as variables instead? That way we'll solve that for free.

@CatarinaGamboa
Copy link
Copy Markdown
Collaborator Author

Can't we treat those as variables instead? That way we'll solve that for free.

we can add a new expression with the equality instead of replacing it, is that what you mean?

@rcosta358
Copy link
Copy Markdown
Collaborator

Yep, exactly, that way we can also expand them to their values in the simplification.

CatarinaGamboa and others added 6 commits May 5, 2026 18:04
Predicates can now use static final primitive/String constants like
Integer.MAX_VALUE or javax.imageio.ImageWriteParam.MODE_DEFAULT directly
inside @refinement strings. Resolution honors the surrounding source
file's imports (single-type and on-demand). When resolution fails but
the reference matches a class in a common JDK package, the verifier
suggests the missing import in the error message.

Refactors the previous Java-side field-read resolution into a single
StaticConstants utility shared by both paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

2 participants