Repository navigation
Make the Purity Checker always pass -AcheckPurityAnnotations
#8264
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
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b9e9a1e
The Purity Checker implies -AcheckPurityAnnotations
smillst b9879e7
Add comment.
smillst 22f83cc
Clarify that -AcheckPurityAnnotations is off by default only for chec…
smillst 5c705d3
Add a documented constructor to PurityChecker
smillst 5702c4d
Use a non-null value for the checkPurityAnnotations option
smillst 090f2f0
Test that the Purity Checker checks purity annotations without -Achec…
smillst b889246
Merge ../checker-framework-branch-master into purity-checker-check-annos
mernst 38a447d
Doc tweaks
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
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
25 changes: 25 additions & 0 deletions
25
framework/src/test/java/org/checkerframework/framework/test/junit/PurityCheckerTest.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,25 @@ | ||
| package org.checkerframework.framework.test.junit; | ||
|
|
||
| import java.io.File; | ||
| import java.util.List; | ||
| import org.checkerframework.framework.test.CheckerFrameworkPerDirectoryTest; | ||
| import org.checkerframework.framework.util.PurityChecker; | ||
| import org.junit.runners.Parameterized.Parameters; | ||
|
|
||
| /** | ||
| * Tests that the Purity Checker issues purity diagnostics without {@code -AcheckPurityAnnotations}. | ||
| */ | ||
| public class PurityCheckerTest extends CheckerFrameworkPerDirectoryTest { | ||
|
|
||
| /** | ||
| * @param testFiles the files containing test code, which will be type-checked | ||
| */ | ||
| public PurityCheckerTest(List<File> testFiles) { | ||
| super(testFiles, PurityChecker.class, "purity-checker"); | ||
| } | ||
|
|
||
| @Parameters | ||
| public static String[] getTestDirs() { | ||
| return new String[] {"purity-checker"}; | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
framework/tests/purity-checker/PurityCheckerChecksAnnotations.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,48 @@ | ||
| // The Purity Checker checks purity annotations even without -AcheckPurityAnnotations. This file | ||
| // holds the same violations as framework/tests/purity-not-checked/PurityMethodRefNotChecked.java, | ||
| // and expects a diagnostic for each of them. | ||
|
|
||
| import org.checkerframework.dataflow.qual.Pure; | ||
| import org.checkerframework.dataflow.qual.SideEffectFree; | ||
|
|
||
| public class PurityCheckerChecksAnnotations { | ||
|
|
||
| int count = 0; | ||
|
|
||
| @FunctionalInterface | ||
| interface PureFunc { | ||
| @Pure | ||
| String doNothing(); | ||
| } | ||
|
|
||
| @FunctionalInterface | ||
| interface SefFunc { | ||
| @SideEffectFree | ||
| String doNothing(); | ||
| } | ||
|
|
||
| static String myMethod() { | ||
| return ""; | ||
| } | ||
|
|
||
| /** A method reference to a method that lacks the functional method's purity. */ | ||
| void methodReference() { | ||
| // :: error: [purity.methodref] | ||
| PureFunc f = PurityCheckerChecksAnnotations::myMethod; | ||
| // :: error: [purity.methodref] | ||
| SefFunc g = PurityCheckerChecksAnnotations::myMethod; | ||
| } | ||
|
|
||
| /** A lambda whose body lacks the functional method's purity. */ | ||
| void lambda() { | ||
| // :: error: [purity.not.sideeffectfree.assign.field] | ||
| SefFunc f = () -> "" + count++; | ||
| } | ||
|
|
||
| /** A method whose body lacks its own purity. */ | ||
| @SideEffectFree | ||
| int assignsField() { | ||
| // :: error: [purity.not.sideeffectfree.assign.field] | ||
| return count++; | ||
| } | ||
| } |
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.
Should this be ratcheted like the Nullness Checker is?
(I can help set that up if needed.)