Repository navigation
Resolve field reads by declaring type and target object #392
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CatarinaGamboa
wants to merge
1
commit into
main
Choose a base branch
from
fix/322-field-resolution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
65 changes: 65 additions & 0 deletions
65
liquidjava-example/src/main/java/testSuite/CorrectFieldReadResolution.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,65 @@ | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.Refinement; | ||
|
|
||
| // #321, #322: field reads resolve to the field of the class and object they name | ||
| public class CorrectFieldReadResolution { | ||
| enum Codec { | ||
| JPG, PNG | ||
| } | ||
|
|
||
| static final int LIMIT = 10; | ||
|
|
||
| @Refinement("val > 0") | ||
| int val; | ||
|
|
||
| int max = 5; | ||
|
|
||
| public CorrectFieldReadResolution(@Refinement("_ > 0") int v) { | ||
| val = v; | ||
| } | ||
|
|
||
| static void onlyPng(@Refinement("_ == Codec.PNG") Codec f) {} | ||
|
|
||
| void otherClass() { | ||
| @Refinement("_ == 10") | ||
| int k = Limits.max; | ||
| @Refinement("_ == 5") | ||
| int m = max; | ||
| @Refinement("_ == 5") | ||
| int t = this.max; | ||
| } | ||
|
|
||
| void otherObject(CorrectFieldReadResolution other) { | ||
| val = 7; | ||
| @Refinement("_ > 0") | ||
| int k = other.val; | ||
| @Refinement("_ > 7") | ||
| int s = val + other.val; | ||
| if (other.val == 3) { | ||
| @Refinement("_ == 7") | ||
| int t = val; | ||
| } | ||
| @Refinement("_ == 7") | ||
| int u = this.val; | ||
| } | ||
|
|
||
| static void sameNamedLocals() { | ||
| Codec JPG = Codec.JPG; | ||
| Codec PNG = Codec.PNG; | ||
| onlyPng(PNG); | ||
| onlyPng(Codec.PNG); | ||
| Codec g = Codec.PNG; | ||
| onlyPng(g); | ||
|
|
||
| int LIMIT = 3; | ||
| @Refinement("_ == 10") | ||
| int k = CorrectFieldReadResolution.LIMIT; | ||
| @Refinement("_ == 3") | ||
| int l = LIMIT; | ||
| } | ||
|
|
||
| static class Limits { | ||
| static final int max = 10; | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
liquidjava-example/src/main/java/testSuite/ErrorFieldOfOtherClass.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,17 @@ | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.Refinement; | ||
|
|
||
| // #322: Limits.max must not be read as this class's own field max | ||
| public class ErrorFieldOfOtherClass { | ||
| int max = 5; | ||
|
|
||
| void check() { | ||
| @Refinement("_ == 5") | ||
| int k = Limits.max; // Expect: Refinement Error | ||
| } | ||
|
|
||
| static class Limits { | ||
| static final int max = 10; | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
liquidjava-example/src/main/java/testSuite/ErrorFieldOfOtherObject.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,41 @@ | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.Refinement; | ||
|
|
||
| // #322: other.val is a different object's field, not this.val | ||
| public class ErrorFieldOfOtherObject { | ||
| @Refinement("val > 0") | ||
| int val; | ||
|
|
||
| public ErrorFieldOfOtherObject(@Refinement("_ > 0") int v) { | ||
| val = v; | ||
| } | ||
|
|
||
| void read(ErrorFieldOfOtherObject other) { | ||
| val = 7; | ||
| @Refinement("_ == 7") | ||
| int k = other.val; // Expect: Refinement Error | ||
| } | ||
|
|
||
| void sum(ErrorFieldOfOtherObject other) { | ||
| val = 7; | ||
| @Refinement("_ == 14") | ||
| int k = val + other.val; // Expect: Refinement Error | ||
| } | ||
|
|
||
| void compound(ErrorFieldOfOtherObject other) { | ||
| val = 7; | ||
| int j = 0; | ||
| j += other.val; | ||
| @Refinement("_ == 7") | ||
| int k = j; // Expect: Refinement Error | ||
| } | ||
|
|
||
| void condition(ErrorFieldOfOtherObject other) { | ||
| val = 7; | ||
| if (other.val == 3) { | ||
| @Refinement("_ == 3") | ||
| int k = val; // Expect: Refinement Error | ||
| } | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
liquidjava-example/src/main/java/testSuite/ErrorLocalShadowsConstant.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,26 @@ | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.Refinement; | ||
|
|
||
| // #321: a local named like a constant must not stand for the constant | ||
| public class ErrorLocalShadowsConstant { | ||
| enum Encoding { | ||
| JPG, PNG | ||
| } | ||
|
|
||
| static final int LIMIT = 10; | ||
|
|
||
| static void onlyPng(@Refinement("_ == Encoding.PNG") Encoding f) {} | ||
|
|
||
| public static void main(String[] args) { | ||
| Encoding JPG = Encoding.PNG; | ||
| Encoding g = Encoding.JPG; | ||
| onlyPng(g); // Expect: Refinement Error | ||
| } | ||
|
|
||
| static void staticConstant() { | ||
| int LIMIT = 3; | ||
| @Refinement("_ == 3") | ||
| int k = ErrorLocalShadowsConstant.LIMIT; // 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
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.