Skip to content

Conversation

@rcosta358
Copy link
Collaborator

This PR adds counterexamples to refinement errors by extracting the SMT model from Z3.

Changes

  • Added the getCounterexample method to TranslatorToZ3 that extracts variable assignments (for constants only)
  • In the SMTEvaluator, when the SMT returns SAT we get the SMT model and throw the TypeCheckError containing the counterexample
  • In the caller methods, instead of returning boolean it now returns Counterexample - if counterexample is null, then the check succeeded, otherwise it failed
  • In the RefinementError, we override the getDetails method to add the counterexamples as extra information in the error message. Also, it filters out fresh variables which don't even exist in the source code, and if the counterexample is the same as the found type (already included in the message), then the counterexample is not shown.

Examples

image image

These will need improvements in the future, especially when dealing with ghosts:

 --> Counterexample: #list_4 == java.util.ArrayList!val!1 && #list_8 == java.util.ArrayList!val!0 && #index_7 == 1

@rcosta358 rcosta358 self-assigned this Feb 10, 2026
@rcosta358 rcosta358 added enhancement New feature or request error messages labels Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request error messages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant