[Eradicate @Nullable checker] Don't apply sub-typing checks for method definitions in the case of constructors.

master
Cristiano Calcagno 10 years ago
parent 0e06f048b7
commit d2e2bbf6a5

@ -534,14 +534,17 @@ let check_overridden_annotations
check_params overriden_proc_name overriden_signature check_params overriden_proc_name overriden_signature
| None -> () in | None -> () in
let check_overriden_methods super_class_name = let check_overridden_methods super_class_name =
let super_proc_name = Procname.java_replace_class proc_name super_class_name in let super_proc_name = Procname.java_replace_class proc_name super_class_name in
let type_name = Sil.TN_csu (Sil.Class, Mangled.from_string super_class_name) in let type_name = Sil.TN_csu (Sil.Class, Mangled.from_string super_class_name) in
match Sil.tenv_lookup tenv type_name with match Sil.tenv_lookup tenv type_name with
| Some (Sil.Tstruct (_, _, _, _, _, methods, _)) -> | Some (Sil.Tstruct (_, _, _, _, _, methods, _)) ->
let is_override pname =
Procname.equal pname super_proc_name &&
not (Procname.is_constructor pname) in
list_iter list_iter
(fun pname -> (fun pname ->
if Procname.equal pname super_proc_name if is_override pname
then check pname) then check pname)
methods methods
| _ -> () in | _ -> () in
@ -555,4 +558,4 @@ let check_overridden_annotations
list_map Mangled.to_string (PatternMatch.type_get_direct_supertypes curr_type) list_map Mangled.to_string (PatternMatch.type_get_direct_supertypes curr_type)
| None -> [] in | None -> [] in
list_iter check_overriden_methods super_types list_iter check_overridden_methods super_types

@ -74,6 +74,19 @@ class SubclassExample {
} }
} }
class ConstructorsAreExcluded {
class Base {
Base (@Nullable String s) {
}
}
class Derived extends Base {
Derived (String s) { // OK: there's no sub-typing between constructors
super(s);
}
}
}
public class InconsistentSubclassAnnotation { public class InconsistentSubclassAnnotation {
public static void callFromSuperclass(SubclassExample.A a) { public static void callFromSuperclass(SubclassExample.A a) {

Loading…
Cancel
Save