Repository navigation
Fix Refinement Declaration Positions #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rcosta358
merged 2 commits into
codex/smt-unknown-error
from
codex/refinement-declaration-position
Oct 6, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
liquidjava-example/src/main/java/testSuite/ErrorRefinementDeclarationPositions.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.Refinement; | ||
| import liquidjava.specification.StateRefinement; | ||
|
|
||
| public class ErrorRefinementDeclarationPositions { | ||
| @Refinement("_ > 10") | ||
| private int field = 11; | ||
|
|
||
| @StateRefinement(from = "true", to = "true") | ||
| @Refinement(value = "_ > 20", msg = "result must exceed twenty") | ||
| int result() { | ||
| return 0; // Expect: Refinement Error | ||
| } | ||
|
|
||
| void parameter(@Refinement("_ > 30") int value) { | ||
| } | ||
|
|
||
| void check() { | ||
| parameter(0); // Expect: Refinement Error | ||
| } | ||
|
|
||
| void local() { | ||
| @Refinement("_ > 40") | ||
| int local = 41; | ||
| local = 0; // Expect: Refinement Error | ||
| } | ||
|
|
||
| void field() { | ||
| field = 0; // Expect: Refinement Error | ||
| } | ||
| } |
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
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
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
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
69 changes: 69 additions & 0 deletions
69
liquidjava-verifier/src/test/java/liquidjava/api/tests/TestDeclarationPositions.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package liquidjava.api.tests; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import liquidjava.api.CommandLineLauncher; | ||
| import liquidjava.diagnostics.Diagnostics; | ||
| import liquidjava.diagnostics.errors.LJError; | ||
| import spoon.reflect.cu.SourcePosition; | ||
|
|
||
| class TestDeclarationPositions { | ||
| @Test | ||
| void smtUnknownPointsToReturnPredicate() throws IOException { | ||
| assertDeclarations("ErrorSMTUnknown.java", "_ > 2.0"); | ||
| } | ||
|
|
||
| @Test | ||
| void refinementErrorPointsToReturnPredicate() throws IOException { | ||
| assertDeclarations("ErrorIdentity.java", "_ > 0"); | ||
| } | ||
|
|
||
| @Test | ||
| void smtUnknownPointsToStatePredicate() throws IOException { | ||
| assertDeclarations("ErrorSMTUnknownState.java", "amount(this) < limit"); | ||
| } | ||
|
|
||
| @Test | ||
| void stateErrorPointsToStatePredicate() throws IOException { | ||
| assertDeclarations("ErrorUnconstrainedStateRefinement.java", "ready(this)"); | ||
| } | ||
|
|
||
| @Test | ||
| void declarationsCoverReturnsParametersLocalsAndFields() throws IOException { | ||
| assertDeclarations("ErrorRefinementDeclarationPositions.java", "_ > 20", "_ > 30", "_ > 40", "_ > 10"); | ||
| } | ||
|
|
||
| private static void assertDeclarations(String file, String... predicates) throws IOException { | ||
| Path path = Path.of("../liquidjava-example/src/main/java/testSuite/", file).toRealPath(); | ||
| String source = Files.readString(path); | ||
| CommandLineLauncher.launch(path.toString()); | ||
| List<LJError> errors = Diagnostics.getInstance().getErrors().stream() | ||
| .sorted(Comparator.comparingInt(error -> error.getPosition().getSourceStart())).toList(); | ||
|
|
||
| assertEquals(predicates.length, errors.size()); | ||
| for (int i = 0; i < predicates.length; i++) { | ||
| LJError error = errors.get(i); | ||
| assertPredicatePosition(error.getDeclarationPosition(), path, source, predicates[i]); | ||
| } | ||
| } | ||
|
|
||
| private static void assertPredicatePosition(SourcePosition position, Path file, String source, String predicate) | ||
| throws IOException { | ||
| assertNotNull(position, "Missing refinement declaration position"); | ||
| assertTrue(position.isValidPosition(), "Invalid refinement declaration position"); | ||
| int start = source.indexOf("\"" + predicate + "\"") + 1; | ||
| assertTrue(start > 0, "Predicate not found in fixture: " + predicate); | ||
| assertEquals(start, position.getSourceStart()); | ||
| assertEquals(start + predicate.length() - 1, position.getSourceEnd()); | ||
| assertEquals(file, position.getFile().toPath().toRealPath()); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should be careful with these string checks cause we might decide change the erro message and then we have to change all these tests. Do you think theres a way to make it less dependendt?