Skip to content

Treat instanceof as an unknown boolean - #359

Merged
CatarinaGamboa merged 1 commit into
mainfrom
fix/335-instanceof
Oct 7, 2026
Merged

CatarinaGamboa merged 1 commit into
mainfrom
fix/335-instanceof

Conversation

@CatarinaGamboa

Copy link
Copy Markdown
Collaborator

Fixes #335.

Problem

instanceof has no counterpart in the refinement language, so getOperatorFromKind returned null for it and any if (o instanceof String) crashed with Cannot invoke "String.hashCode()" because "<local1>" is null, even in a file without refinements.

Change

OperationsChecker treats instanceof the way it already treats comparisons with null: the result is a fresh, unconstrained boolean (isUntranslatable covers both, in the binary-operator and the assignment paths). Both branches stay reachable, so nothing is assumed from the test.

Tests

  • CorrectInstanceof: instanceof in an if, bound to a boolean local and combined with &&, and negated inside ||. Crashed on main, now passes.
  • ErrorInstanceof: a refinement violation inside an instanceof branch is reported (crashed on main).
  • Pattern matching (o instanceof String s && !s.isEmpty()) also verifies.
  • mvn test passes.

🤖 Generated with Claude Code

@CatarinaGamboa CatarinaGamboa added the bug Something isn't working label Oct 7, 2026
Fixes #335. instanceof had no operator in the refinement language, so any
`if (x instanceof T)` crashed with a NullPointerException. It is now a fresh
boolean, as null comparisons already are: both branches stay reachable and
verification continues.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CatarinaGamboa
CatarinaGamboa merged commit ef1603d into main Oct 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verifier crashes on instanceof in an if condition

2 participants