Skip to content

Support length on arrays of any element type - #357

Merged
CatarinaGamboa merged 1 commit into
mainfrom
fix/355-array-length
Oct 7, 2026
Merged

CatarinaGamboa merged 1 commit into
mainfrom
fix/355-array-length

Conversation

@CatarinaGamboa

Copy link
Copy Markdown
Collaborator

Fixes #355.

Problem

The builtin length was declared as (declare-fun length ((Array Int Int)) Int), for int[] only. Any other array's .length in the context (a for (int i = 0; i < names.length; i++) loop over a String[]) made every Z3 query in that scope crash with Sort mismatch at argument #1 for function (declare-fun length ((Array Int Int)) Int) supplied sort is |java.lang.String[]|.

Change

TranslatorToZ3.makeFunctionInvocation routes length to makeLength, which uses the builtin declaration for int[] and otherwise declares (once per sort, cached) a length overload whose domain is the array's sort.

Tests

  • CorrectStringArrayLength: a loop bounded by names.length over a refined String[], plus length(names) > 0 flowing into _ > 0; crashed on main, now passes.
  • ErrorStringArrayLength: length(names) >= 0 does not give _ > 0; crashed on main, now the Refinement Error.
  • mvn test passes.

🤖 Generated with Claude Code

Fixes #355. The builtin length was declared for int[] only, so .length of
any other array (String[], Object[], ...) in the context made every Z3 query
fail with a sort mismatch. length now gets one overload per array sort,
declared on first use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CatarinaGamboa CatarinaGamboa added the enhancement New feature or request label Oct 7, 2026

@rcosta358 rcosta358 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Cool!

@CatarinaGamboa
CatarinaGamboa merged commit ffd51c6 into main Oct 7, 2026
1 check passed
@rcosta358
rcosta358 deleted the fix/355-array-length branch October 13, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verifier crashes with a sort mismatch on .length of a non-int array

2 participants