Repository navigation
Support length on arrays of any element type - #357
Open
CatarinaGamboa wants to merge 1 commit into
Open
CatarinaGamboa wants to merge 1 commit into
CatarinaGamboa wants to merge 1 commit into
Conversation
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>
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.
Fixes #355.
Problem
The builtin
lengthwas declared as(declare-fun length ((Array Int Int)) Int), forint[]only. Any other array's.lengthin the context (afor (int i = 0; i < names.length; i++)loop over aString[]) made every Z3 query in that scope crash withSort mismatch at argument #1 for function (declare-fun length ((Array Int Int)) Int) supplied sort is |java.lang.String[]|.Change
TranslatorToZ3.makeFunctionInvocationrouteslengthtomakeLength, which uses the builtin declaration forint[]and otherwise declares (once per sort, cached) alengthoverload whose domain is the array's sort.Tests
CorrectStringArrayLength: a loop bounded bynames.lengthover a refinedString[], pluslength(names) > 0flowing into_ > 0; crashed on main, now passes.ErrorStringArrayLength:length(names) >= 0does not give_ > 0; crashed on main, now the Refinement Error.mvn testpasses.🤖 Generated with Claude Code