Skip to content

Support length on arrays of any element type - #357

Open
CatarinaGamboa wants to merge 1 commit into
mainfrom
fix/355-array-length
Open

CatarinaGamboa wants to merge 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>
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.

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

1 participant