From fda7f4aa8c5cb74a9fa9f9da6ae79020cbd6cf1a Mon Sep 17 00:00:00 2001 From: Mitya Lyubarskiy Date: Fri, 24 Apr 2020 06:22:48 -0700 Subject: [PATCH] [nullsafe] Anonymous classes should inherit mode from the user-defined nested owner Summary: Because of this bug, we evaluated anonymous class constructors in Default mode, even if the underlying class was Nullsafe Reviewed By: artempyanykh Differential Revision: D21202986 fbshipit-source-id: a31318901 --- infer/src/nullsafe/NullsafeMode.ml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/infer/src/nullsafe/NullsafeMode.ml b/infer/src/nullsafe/NullsafeMode.ml index d0d94f9cc..179dba219 100644 --- a/infer/src/nullsafe/NullsafeMode.ml +++ b/infer/src/nullsafe/NullsafeMode.ml @@ -103,8 +103,19 @@ let of_annot annot = None +let extract_user_defined_class_name typ_name = + match typ_name with + | Typ.JavaClass java_class_name -> + (* Anonymous inner classes are not proper classes and can not be annotated. Refer to underlying user class *) + JavaClassName.get_user_defined_class_if_anonymous_inner java_class_name + |> Option.value ~default:java_class_name + | _ -> + Logging.die InternalError "Unexpected non-Java class name" + + let of_class tenv typ_name = - match PatternMatch.type_name_get_annotation tenv typ_name with + let user_defined_class = extract_user_defined_class_name typ_name in + match PatternMatch.type_name_get_annotation tenv (Typ.JavaClass user_defined_class) with | Some annots -> ( if Annotations.ia_is_nullsafe_strict annots then Strict else