Repository navigation
Commit ffd51c6
Support length on arrays of any element type (#357)
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](https://claude.com/claude-code)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent a4fbebe commit ffd51c6
3 files changed
Lines changed: 48 additions & 0 deletions
File tree
- liquidjava-example/src/main/java/testSuite
- liquidjava-verifier/src/main/java/liquidjava/smt
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
163 | 164 | | |
164 | 165 | | |
165 | 166 | | |
| 167 | + | |
| 168 | + | |
166 | 169 | | |
167 | 170 | | |
168 | 171 | | |
| |||
185 | 188 | | |
186 | 189 | | |
187 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
188 | 205 | | |
189 | 206 | | |
190 | 207 | | |
| |||
0 commit comments