-
Notifications
You must be signed in to change notification settings - Fork 435
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
base: master
Are you sure you want to change the base?
Filter dependent type annotations referencing out-of-scope local vari… #7448
Conversation
📝 WalkthroughWalkthroughAdds a public test class ScopeCleanup with two methods testing dependent-annotation scope cleanup and parameter scoping. Exposes tracked local variables via CFAbstractStore.getLocalVariables(). GenericAnnotatedTypeFactory now filters inferred dependent annotations that reference out-of-scope locals by consulting the store before the current tree. Adds DependentTypesHelper.filterAnnotationsForOutOfScopeVars(...) to remove dependent annotations whose expressions reference locals not in a provided in-scope set. Appends "Shubham Kapoor" to docs/manual/contributors.tex. Suggested reviewers
🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@checker/tests/index/ScopeCleanup.java`:
- Around line 46-58: The test method testParametersRemainInScope lacks any
assertion that uses the parameter after the inner block; add an assignment or
assertion that uses the dependent annotation `@LessThan`("param") (for example
assign a variable annotated `@LessThan`("param") to x or similar) after the inner
block so the checker actually validates that the method parameter param remains
in scope; target the testParametersRemainInScope method and add the annotated
assignment/verification immediately after the closing brace of the inner block
to exercise scope retention.
In
`@framework/src/main/java/org/checkerframework/framework/util/dependenttypes/DependentTypesHelper.java`:
- Around line 781-812: The code in DependentTypesHelper currently calls
StringToJavaExpression.atPath(...) without handling
JavaExpressionParseException; wrap the call to StringToJavaExpression.atPath in
a try/catch that catches JavaExpressionParseException and returns null (dropping
the expression) so parse failures don't produce error annotations; keep the
existing JavaExpressionConverter logic and only catch
JavaExpressionParseException from the atPath invocation (rethrow or preserve
other exceptions).
...k/src/main/java/org/checkerframework/framework/util/dependenttypes/DependentTypesHelper.java
Show resolved
Hide resolved
eb18561 to
f541d23
Compare
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@framework/src/main/java/org/checkerframework/framework/type/GenericAnnotatedTypeFactory.java`:
- Around line 1993-2001: The current logic uses Store store =
getStoreBefore(tree); Set<LocalVariable> inScopeVars =
store.getLocalVariables(); which omits syntactically in-scope locals that are
unassigned (TOP), causing valid dependent annotations to be filtered; replace
this by deriving the set of in-scope locals from a scope/syntactic source (e.g.,
the scope for the tree or a helper that returns all local variable symbols for
the current path) or merge store.getLocalVariables() with the syntactic scope's
locals so unassigned locals are included, then pass that complete set into
dependentTypesHelper.filterAnnotationsForOutOfScopeVars(type, inScopeVars,
getPath(tree)); ensure parameters keep their existing special-case handling
analogously.
framework/src/main/java/org/checkerframework/framework/type/GenericAnnotatedTypeFactory.java
Show resolved
Hide resolved
|
@shubhamk0205 Please let us know when you have resolved the CI test failures (or if you need help with them). |
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@framework/src/main/java/org/checkerframework/framework/util/dependenttypes/DependentTypesHelper.java`:
- Around line 781-786: The lambda assigned to StringToJavaExpression
(stringToJavaExpr) contains a redundant shouldPassThroughExpression check and
creation of PassThroughExpression because convertAnnotationMirror already skips
invoking stringToJavaExpr for pass-through cases; remove that conditional branch
from the lambda so stringToJavaExpr only handles non-pass-through conversion
paths (leave references to objectTM and any remaining expression handling
intact) and ensure all pass-through behavior remains centralized in
convertAnnotationMirror rather than inside stringToJavaExpr.
...k/src/main/java/org/checkerframework/framework/util/dependenttypes/DependentTypesHelper.java
Outdated
Show resolved
Hide resolved
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@framework/src/main/java/org/checkerframework/framework/util/dependenttypes/DependentTypesHelper.java`:
- Around line 771-772: The method filterAnnotationsForOutOfScopeVars declares a
null guard and Javadoc implying that the TreePath parameter may be null but the
signature lacks a nullability annotation; update the method signature to mark
the path parameter as `@Nullable` (e.g., change TreePath path to `@Nullable`
TreePath path), add or update the Javadoc to state that path may be null, and
import the project's nullability annotation (use the project's standard
annotation, e.g., org.checkerframework.checker.nullness.qual.Nullable) so
nullness analysis is consistent with the implementation in
DependentTypesHelper.filterAnnotationsForOutOfScopeVars.
...k/src/main/java/org/checkerframework/framework/util/dependenttypes/DependentTypesHelper.java
Outdated
Show resolved
Hide resolved
|
@mernst can u guide me a little i am a bit stuck here , i have tried to make the current filtering approach work , for example - now one option to be somehow fix this and the other one would be to follow the second approach that u mentioned what would you prefer ? |
solves #4105
this pr makes dependent type annotations aware of the scope . after the annotations are applied , any annotation that refers to a local variable that is now not present in the scope is getting removed automatically .
i have also added a test case file in the pr