-
Notifications
You must be signed in to change notification settings - Fork 438
Filter dependent type annotations referencing out-of-scope local vari… #7448
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
Open
shubhamk0205
wants to merge
7
commits into
typetools:master
Choose a base branch
from
shubhamk0205:fix/scope-cleanup-dependent-type-annotations
base: master
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 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f541d23
Filter dependent type annotations referencing out-of-scope local vari…
shubhamk0205 f291a9c
fixed bug
shubhamk0205 b011a3d
fixed redundandt code
shubhamk0205 c93d8a3
fixed nullable path
shubhamk0205 796f992
Merge ../checker-framework-branch-master into fix/scope-cleanup-depen…
mernst 3ee7f37
Merge ../checker-framework-branch-master into fix/scope-cleanup-depen…
mernst c62d3a1
Merge ../checker-framework-branch-master into fix/scope-cleanup-depen…
mernst 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
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,60 @@ | ||
| import org.checkerframework.checker.index.qual.LessThan; | ||
| import org.checkerframework.checker.index.qual.NonNegative; | ||
|
|
||
| /** | ||
| * Test case for scope cleanup of dependent type annotations. | ||
| * | ||
| * <p>When a local variable goes out of scope, any dependent type annotation that references that | ||
| * variable should be invalidated. This test verifies that annotations like @LessThan("b") on | ||
| * variable 'a' are properly dropped when 'b' goes out of scope. | ||
| */ | ||
| public class ScopeCleanup { | ||
|
|
||
| /** | ||
| * Test that @LessThan annotation is properly cleaned up when the referenced variable goes out of | ||
| * scope. | ||
| */ | ||
| void testScopeCleanup() { | ||
| int a = 5; | ||
|
|
||
| { | ||
| int b = 10; | ||
| a = b - 1; | ||
| // At this point, 'a' should have type @LessThan("b") and that's correct. | ||
|
|
||
| // This should be fine: a < b is true | ||
| @LessThan("b") int shouldWork = a; | ||
| } | ||
|
|
||
| // After exiting scope, 'b' is no longer in scope. | ||
| // The @LessThan("b") annotation on 'a' should be dropped. | ||
| // However, non-dependent annotations should survive. | ||
| @NonNegative int ok = a; // This should still work - a is still non-negative (a=9) | ||
|
|
||
| { | ||
| int b = 3; // Different variable 'b' with a smaller value! | ||
| // Without the fix, the old @LessThan("b") annotation would incorrectly refer to THIS 'b'. | ||
| // But a = 9 and this b = 3, so a > b, not a < b. | ||
|
|
||
| // This should be an error - we can no longer prove a < b | ||
| // The assignment below should fail type-checking because we can't prove a < b | ||
| // :: error: (assignment) | ||
| @LessThan("b") int shouldFail = a; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Test that method parameters are not affected by scope cleanup (they should always be considered | ||
| * in scope). | ||
| */ | ||
| void testParametersRemainInScope(@NonNegative int param) { | ||
| int x; | ||
| { | ||
| int localVar = param + 1; | ||
| x = param - 1; // x < param should be valid | ||
| } | ||
| // Even after the block ends, 'param' is still in scope, so @LessThan("param") should be valid | ||
| // This test ensures method parameters are handled correctly | ||
| @LessThan("param") int shouldWork = x; | ||
| } | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.