Repository navigation
Commit 9045ecd
Treat catch parameters as variables with unknown state (#362)
Closes #333.
A catch parameter was never added to the verification context. As a
result:
1. Calls on it skipped typestate checks (`x.initCause(t)` on a caught
`Throwable` passed).
2. It took the state of an earlier, out-of-scope local with the same
name.
3. Assigning it to another variable failed with `Variable 'e' could not
be found`.
**Fix**
- `RefinementTypeChecker#visitCtCatchVariable` registers the catch
parameter like a method parameter: a new variable whose state is
unknown.
- Before that, `Context#removeVarFromContext` drops any variable with
the same name. Java forbids a catch parameter from shadowing a local
that is in scope, so such an entry is always a stale, out-of-scope
local. Fields cannot clash because they are stored under qualified
`this#…` names.
**Tests**
`testSuite/classes/catch_parameter_error` covers the three reproducers.
Each now reports the same "found true but expected noThrowable(…)" error
as the method-parameter case.
**Not fixed here**
Reproducer 3 as written in the issue (`catch (Exception e)` assigned to
a `Throwable` local) now fails with `Sorts java.lang.Throwable and
java.lang.Exception are incompatible`. This bug is separate and already
present on `main`: assigning a subtype to a supertype variable fails the
same way when the subtype comes from a method parameter. The test
therefore uses `catch (Throwable e)` for that case.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent ef1603d commit 9045ecd
4 files changed
Lines changed: 74 additions & 0 deletions
File tree
- liquidjava-example/src/main/java/testSuite/classes/catch_parameter_error
- liquidjava-verifier/src/main/java/liquidjava/processor
- context
- refinement_checker
Lines changed: 41 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 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
liquidjava-example/src/main/java/testSuite/classes/catch_parameter_error/ThrowableRefinements.java
Lines changed: 18 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 | + | |
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
152 | 157 | | |
153 | 158 | | |
154 | 159 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
179 | 180 | | |
180 | 181 | | |
181 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
182 | 192 | | |
183 | 193 | | |
184 | 194 | | |
| |||
0 commit comments