[infer][java] Eradicate should not report a Return Not Nullable when a method returns the integer 0

Summary: This was causing false positives when returning the constant integer 0.

Reviewed By: sblackshear

Differential Revision: D7330143

fbshipit-source-id: 45d19dd
master
Jeremy Dubreil 7 years ago committed by Facebook Github Bot
parent 1ea4f01403
commit e801617488

@ -147,6 +147,11 @@ type checks = {eradicate: bool; check_extension: bool; check_ret_type: check_ret
let rec typecheck_expr find_canonical_duplicate visited checks tenv node instr_ref let rec typecheck_expr find_canonical_duplicate visited checks tenv node instr_ref
(curr_pdesc: Procdesc.t) typestate e tr_default loc : TypeState.range = (curr_pdesc: Procdesc.t) typestate e tr_default loc : TypeState.range =
match e with match e with
| _ when Exp.is_null_literal e ->
let typ, ta, locs = tr_default in
if PatternMatch.type_is_class typ then
(typ, TypeAnnotation.const AnnotatedSignature.Nullable true (TypeOrigin.Const loc), locs)
else (typ, TypeAnnotation.with_origin ta (TypeOrigin.Const loc), locs)
| Exp.Lvar pvar -> ( | Exp.Lvar pvar -> (
match TypeState.lookup_pvar pvar typestate with match TypeState.lookup_pvar pvar typestate with
| Some tr -> | Some tr ->
@ -159,13 +164,6 @@ let rec typecheck_expr find_canonical_duplicate visited checks tenv node instr_r
TypeState.range_add_locs tr [loc] TypeState.range_add_locs tr [loc]
| None -> | None ->
tr_default ) tr_default )
| Exp.Const Const.Cint i when IntLit.iszero i ->
let typ, _, locs = tr_default in
if PatternMatch.type_is_class typ then
(typ, TypeAnnotation.const AnnotatedSignature.Nullable true (TypeOrigin.Const loc), locs)
else
let t, ta, ll = tr_default in
(t, TypeAnnotation.with_origin ta (TypeOrigin.Const loc), ll)
| Exp.Exn e1 -> | Exp.Exn e1 ->
typecheck_expr find_canonical_duplicate visited checks tenv node instr_ref curr_pdesc typecheck_expr find_canonical_duplicate visited checks tenv node instr_ref curr_pdesc
typestate e1 tr_default loc typestate e1 tr_default loc

@ -155,4 +155,12 @@ public class ReturnNotNullable {
Object $generatedReturnsNullOk() { Object $generatedReturnsNullOk() {
return null; return null;
} }
int field;
int returnsZero() {
field = 0;
return field;
}
} }

Loading…
Cancel
Save