diff --git a/infer/src/eradicate/typeState.ml b/infer/src/eradicate/typeState.ml index 2ba4be3ee..700ef0b98 100644 --- a/infer/src/eradicate/typeState.ml +++ b/infer/src/eradicate/typeState.ml @@ -84,7 +84,7 @@ let range_add_locs (typ, ta, locs1) locs2 = let locs' = locs_join locs1 locs2 in (typ, ta, locs') -(** Join m2 to m1 if there are no inconsistencies, otherwise return t1. *) +(** Join m2 to m1 if there are no inconsistencies, otherwise return m1. *) let map_join m1 m2 = let tjoined = ref m1 in let range_join (typ1, ta1, locs1) (typ2, ta2, locs2) = @@ -101,11 +101,7 @@ let map_join m1 m2 = | None -> () | Some range' -> tjoined := M.add exp2 range' !tjoined) with Not_found -> - let (t2, ta2, locs2) = range2 in - let range2' = - let ta2' = TypeAnnotation.with_origin ta2 TypeOrigin.Undef in - (t2, ta2', locs2) in - tjoined := M.add exp2 range2' !tjoined in + tjoined := M.add exp2 range2 !tjoined in let missing_rhs exp1 range1 = (* handle elements missing in the rhs *) try ignore (M.find exp1 m2) @@ -123,6 +119,10 @@ let map_join m1 m2 = ) let join ext t1 t2 = + if Config.from_env_variable "ERADICATE_TRACE" + then L.stderr "@.@.**********join@.-------@.%a@.------@.%a@.********@.@." + (pp ext) t1 + (pp ext) t2; { map = map_join t1.map t2.map; extension = ext.join t1.extension t2.extension; diff --git a/infer/tests/codetoanalyze/java/eradicate/FieldNotNullable.java b/infer/tests/codetoanalyze/java/eradicate/FieldNotNullable.java index b55677c26..fce121fb1 100644 --- a/infer/tests/codetoanalyze/java/eradicate/FieldNotNullable.java +++ b/infer/tests/codetoanalyze/java/eradicate/FieldNotNullable.java @@ -357,6 +357,14 @@ class NestedFieldAccess { } } + void testMapContainsKeyInsideWhileLoop (java.util.Map m) { + while (true) { + if (m.containsKey(3)) { + m.get(3).isEmpty(); + } + } + } + void testImmutableMapContainsKey (com.google.common.collect.ImmutableMap m) { if (m.containsKey(3)) { m.get(3).isEmpty();