-
Notifications
You must be signed in to change notification settings - Fork 29
Viewpoint test checker: lost receiver invoke poly receiver method #1173
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?
Changes from 8 commits
d0a276c
317695b
81d996f
0150bc2
523ad9d
30b6f7f
a29edf8
539258a
508ed8e
6bfa875
175580c
f500969
d8d5584
8c4b0ec
04ddd85
e900407
6e4526b
7ccef46
a3f0891
ceeab99
8a68568
62a178f
8a41e41
625ab89
2c274b4
0592b0e
c72da59
b795476
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,15 @@ | ||
| package viewpointtest; | ||
|
|
||
| import com.sun.source.tree.AssignmentTree; | ||
| import com.sun.source.tree.CompoundAssignmentTree; | ||
| import com.sun.source.tree.NewClassTree; | ||
| import com.sun.source.tree.Tree; | ||
| import com.sun.source.tree.UnaryTree; | ||
|
|
||
| import org.checkerframework.common.basetype.BaseTypeChecker; | ||
| import org.checkerframework.common.basetype.BaseTypeVisitor; | ||
| import org.checkerframework.framework.type.AnnotatedTypeMirror; | ||
| import org.checkerframework.framework.util.AnnotatedTypes; | ||
|
|
||
| /** The visitor for the Viewpoint Test Checker. */ | ||
| public class ViewpointTestVisitor extends BaseTypeVisitor<ViewpointTestAnnotatedTypeFactory> { | ||
|
|
@@ -19,10 +24,48 @@ public ViewpointTestVisitor(BaseTypeChecker checker) { | |
|
|
||
| @Override | ||
| public Void visitNewClass(NewClassTree tree, Void p) { | ||
| AnnotatedTypeMirror Type = atypeFactory.getAnnotatedType(tree); | ||
| if (Type.hasAnnotation(atypeFactory.TOP) || Type.hasAnnotation(atypeFactory.LOST)) { | ||
| checker.reportError(tree, "new.class.type.invalid", Type.getAnnotations()); | ||
| AnnotatedTypeMirror type = atypeFactory.getAnnotatedType(tree); | ||
| if (type.hasAnnotation(atypeFactory.TOP) || type.hasAnnotation(atypeFactory.LOST)) { | ||
| checker.reportError(tree, "new.class.type.invalid", type.getAnnotations()); | ||
| } | ||
| return super.visitNewClass(tree, p); | ||
| } | ||
|
|
||
| @Override | ||
| public Void visitAssignment(AssignmentTree tree, Void p) { | ||
| checkLostLhs(tree.getVariable(), tree); | ||
| return super.visitAssignment(tree, p); | ||
| } | ||
|
|
||
| @Override | ||
| public Void visitCompoundAssignment(CompoundAssignmentTree tree, Void p) { | ||
| checkLostLhs(tree.getVariable(), tree); | ||
| return super.visitCompoundAssignment(tree, p); | ||
| } | ||
|
|
||
| @Override | ||
| public Void visitUnary(UnaryTree tree, Void p) { | ||
| Tree.Kind treeKind = tree.getKind(); | ||
| if (treeKind == Tree.Kind.PREFIX_DECREMENT | ||
| || treeKind == Tree.Kind.PREFIX_INCREMENT | ||
| || treeKind == Tree.Kind.POSTFIX_DECREMENT | ||
| || treeKind == Tree.Kind.POSTFIX_INCREMENT) { | ||
| checkLostLhs(tree.getExpression(), tree); | ||
| } | ||
| return super.visitUnary(tree, p); | ||
| } | ||
|
|
||
| /** | ||
| * Report an error if {@code variableTree}, interpreted as an assignment left-hand side, | ||
| * contains {@code @Lost}. | ||
| * | ||
| * @param variableTree the assignment target to check | ||
| * @param errorTree the tree on which to report the error | ||
| */ | ||
| private void checkLostLhs(Tree variableTree, Tree errorTree) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be easier to just override What about the adapted parameter type becoming Lost? Is there no check needed there? Is there a test for this?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed. I followed the same split used by the Universe checker: UniverseVisitor reports separate diagnostics for UniverseTypeValidator separately checks for This PR now mirrors that structure for the Viewpoint test checker: I also added tests for the adapted-parameter and adapted-bound cases, including LostInBounds. |
||
| AnnotatedTypeMirror variableType = atypeFactory.getAnnotatedTypeLhs(variableTree); | ||
| if (AnnotatedTypes.containsModifier(variableType, atypeFactory.LOST)) { | ||
| checker.reportError(errorTree, "viewpointtest.lost.lhs"); | ||
|
aosen-xiong marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.