Skip to content

Commit

Permalink
Handle boxed primitives in the Signedness Checker
Browse files Browse the repository at this point in the history
  • Loading branch information
mernst committed Jul 6, 2020
1 parent 70cc4f2 commit 83305b2
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@
TypeKind.FLOAT,
TypeKind.DOUBLE,
TypeKind.CHAR
}

// This is commented out until implicitly signed boxed types are implemented
// correctly.

/*,
},
types = {
java.lang.Byte.class,
java.lang.Short.class,
java.lang.Integer.class,
java.lang.Long.class
}*/ )
java.lang.Long.class,
java.lang.Short.class,
java.lang.Float.class,
java.lang.Double.class,
java.lang.Character.class
})
public @interface Signed {}
83 changes: 83 additions & 0 deletions checker/tests/signedness/BoxedPrimitives.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import java.util.LinkedList;
import org.checkerframework.checker.signedness.qual.Signed;
import org.checkerframework.checker.signedness.qual.Unsigned;

public class BoxedPrimitives {

@Signed int si;
@Unsigned int ui;

@Signed Integer sbi;
@Unsigned Integer ubi;

void argSigned(@Signed int x) {
si = x;
sbi = x;
// :: error: (assignment.type.incompatible)
ui = x;
// :: error: (assignment.type.incompatible)
ubi = x;
}

void argUnsigned(@Unsigned int x) {
// :: error: (assignment.type.incompatible)
si = x;
// :: error: (assignment.type.incompatible)
sbi = x;
ui = x;
ubi = x;
}

void argSignedBoxed(@Signed Integer x) {
si = x;
sbi = x;
// :: error: (assignment.type.incompatible)
ui = x;
// :: error: (assignment.type.incompatible)
ubi = x;
}

void argUnsignedBoxed(@Unsigned Integer x) {
// :: error: (assignment.type.incompatible)
si = x;
// :: error: (assignment.type.incompatible)
sbi = x;
ui = x;
ubi = x;
}

void client() {
argSigned(si);
argSignedBoxed(si);
argSigned(sbi);
argSignedBoxed(sbi);
// :: error: (argument.type.incompatible)
argUnsigned(si);
// :: error: (argument.type.incompatible)
argUnsignedBoxed(si);
// :: error: (argument.type.incompatible)
argUnsigned(sbi);
// :: error: (argument.type.incompatible)
argUnsignedBoxed(sbi);
// :: error: (argument.type.incompatible)
argSigned(ui);
// :: error: (argument.type.incompatible)
argSignedBoxed(ui);
// :: error: (argument.type.incompatible)
argSigned(ubi);
// :: error: (argument.type.incompatible)
argSignedBoxed(ubi);
argUnsigned(ui);
argUnsignedBoxed(ui);
argUnsigned(ubi);
argUnsignedBoxed(ubi);
}

public LinkedList<Integer> commands;

void forLoop() {
for (Integer ix : this.commands) {
argSigned(ix);
}
}
}
6 changes: 4 additions & 2 deletions framework/tests/all-systems/GetClassTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ void context() {
// Type arguments don't match
@SuppressWarnings("fenum:assignment.type.incompatible")
Class<? extends Object> b = i.getClass();
// Type arguments don't match
@SuppressWarnings("fenum:assignment.type.incompatible")
@SuppressWarnings({
"fenum:assignment.type.incompatible", // Type arguments don't match
"signedness:assignment.type.incompatible" // Type arguments don't match
})
Class<? extends Integer> c = i.getClass();

Class<?> d = i.getClass();
Expand Down
1 change: 1 addition & 0 deletions framework/tests/all-systems/Issue457.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Issue457<T extends Number> {
public void f(T t) {
final T obj = t;

@SuppressWarnings("signedness:assignment.type.incompatible") // cast
Float objFloat = (obj instanceof Float) ? (Float) obj : null;

// An error will be emitted on this line before the fix for Issue457
Expand Down

0 comments on commit 83305b2

Please sign in to comment.