Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;

public class PurityError {
public class VoidMethodIsDeterministic {
@SideEffectFree
void method() {}

@Pure
Object method2() {
// :: error: [purity.not.deterministic.call]
method();
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;
import org.checkerframework.dataflow.qual.Deterministic;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
Expand Down Expand Up @@ -260,7 +261,10 @@ public Void visitMethodInvocation(MethodInvocationTree tree, Void ignore) {
// Avoid computation if not necessary
? detAndSeFree
: PurityUtils.getPurityKinds(annoProvider, elt);
boolean det = assumeDeterministic || purityKinds.contains(Pure.Kind.DETERMINISTIC);
boolean det =
assumeDeterministic
|| purityKinds.contains(Pure.Kind.DETERMINISTIC)
|| elt.getReturnType().getKind() == TypeKind.VOID;
Comment thread
mernst marked this conversation as resolved.
boolean seFree = assumeSideEffectFree || purityKinds.contains(Pure.Kind.SIDE_EFFECT_FREE);
if (!det && !seFree) {
purityResult.addNotBothReason(tree, "call");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ unallowed.access=access of the field (%s) is not permitted on receiver of type (
cast.redundant=Redundant cast;%ntype : %s

# TODO: The call.{constructor,method} messages should take an argument indicating which method or constructor is the problem
purity.deterministic.constructor=a constructor cannot be deterministic
purity.deterministic.void.method=a method without return value cannot be deterministic
purity.deterministic.constructor=a constructor cannot be annotated @Deterministic
purity.deterministic.void.method=a method without return value cannot be annotated @Deterministic
purity.methodref=Incompatible purity declaration%nMethod in %s%n %s%n is not a valid method reference for method in %s%n %s%nfound : %s%nrequired: %s
purity.overriding=Incompatible purity declaration%nMethod in %s%n %s%n cannot override method in %s%n %s%nfound : %s%nrequired: %s
purity.not.deterministic.assign.array=array assignment not allowed in deterministic method
Expand Down
21 changes: 21 additions & 0 deletions framework/tests/purity-suggestions/SideEffectFreeVoidMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;

public class SideEffectFreeVoidMethod {

int size;

@Pure
private int getOrNull(int index) {
assertIndexInBounds(index, "getOrNull");
return 22;
}

@SideEffectFree
private void assertIndexInBounds(int index, String method) {
if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException(
method + "(" + index + ",...) called on ArrayMap of size " + size);
}
}
}
2 changes: 1 addition & 1 deletion release.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ext {
// * any new checkers have been added, or
// * backward-incompatible changes have been made to APIs or elsewhere.
// To make a snapshot release, version should end in "-SNAPSHOT", then: ./gradlew publish
releaseVersion = "4.1.0"
releaseVersion = "4.1.1-SNAPSHOT"

releaseVersionRegex = "\\d\\.\\d+\\.\\d+(?:\\.\\d)?"

Expand Down