[nullsafe] Don't join types in a fancy way.

Summary:
The goal of this logic is unclear:
1/ See the comments
2/ I can not see the scenario where classes and proper types can be
joined in a legit Java program
3/ Even it if was the case, I don't see how this heuristic is justified.
So I assume it is not.

Reviewed By: artempyanykh

Differential Revision: D17876568

fbshipit-source-id: c9c6cd604
master
Mitya Lyubarskiy 5 years ago committed by Facebook Github Bot
parent cf6c78a64a
commit 303263eb2e

@ -9,14 +9,6 @@ open! IStd
(** Module for Pattern matching. *)
let type_is_object typ =
match typ.Typ.desc with
| Tptr ({desc= Tstruct name}, _) ->
Typ.Name.equal name Typ.Name.Java.java_lang_object
| _ ->
false
(** Holds iff the predicate holds on a supertype of the named type, including the type itself *)
let rec supertype_exists tenv pred name =
match Tenv.lookup tenv name with

@ -132,9 +132,6 @@ val type_get_class_name : Typ.t -> Typ.Name.t option
val type_is_class : Typ.t -> bool
(** Is the type a class type *)
val type_is_object : Typ.t -> bool
(** Is the type java.lang.Object *)
val get_fields_nullified : Procdesc.t -> Typ.Fieldname.Set.t
(** return the set of instance fields that are assigned to a null literal in [procdesc] *)

@ -36,17 +36,21 @@ let pp fmt typestate =
pp_map typestate
let type_join typ1 typ2 = if PatternMatch.type_is_object typ1 then typ2 else typ1
let map_join m1 m2 =
let range_join _exp range1_opt range2_opt =
Option.both range1_opt range2_opt
|> Option.map
~f:(fun (((typ1, inferred_nullability1) as range1), (typ2, inferred_nullability2)) ->
~f:(fun (((typ1, inferred_nullability1) as range1), (_, inferred_nullability2)) ->
InferredNullability.join inferred_nullability1 inferred_nullability2
|> Option.value_map ~default:range1 ~f:(fun ta' ->
let typ' = type_join typ1 typ2 in
(typ', ta') ) )
( (* Java does not support local type inference (for codebases and Java version nullsafe is currently aimed for).
The real type does not depend on types being joined; it is determined by the corresponding type declaration instead.
We don't really use type information for reasons not related to things like diagnostic, and using one of types
serves as a good proxy.
Let's take the left one.
*)
typ1
, ta' ) ) )
in
if phys_equal m1 m2 then m1 else M.merge range_join m1 m2

Loading…
Cancel
Save