[linters] Do not report MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE for the loop indices

Reviewed By: jvillard

Differential Revision: D5964060

fbshipit-source-id: 5998eff
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent 85e4707d00
commit e5007cf2e0

@ -25,7 +25,8 @@ type context =
(** If inside an objc class, contains the objc class (impl or interface) decl. *) (** If inside an objc class, contains the objc class (impl or interface) decl. *)
; current_objc_class: Clang_ast_t.decl option ; current_objc_class: Clang_ast_t.decl option
; et_evaluation_node: string option ; et_evaluation_node: string option
; if_context: if_context option } ; if_context: if_context option
; in_for_loop_declaration: bool }
let empty translation_unit_context = let empty translation_unit_context =
{ current_method= None { current_method= None
@ -35,7 +36,8 @@ let empty translation_unit_context =
; is_ck_translation_unit= false ; is_ck_translation_unit= false
; current_objc_class= None ; current_objc_class= None
; et_evaluation_node= None ; et_evaluation_node= None
; if_context= None } ; if_context= None
; in_for_loop_declaration= false }
let add_parent_method decl_opt parent_methods = let add_parent_method decl_opt parent_methods =
match decl_opt with Some decl -> decl :: parent_methods | None -> parent_methods match decl_opt with Some decl -> decl :: parent_methods | None -> parent_methods

@ -25,7 +25,8 @@ type context =
(** If inside an objc class, contains the objc class (impl or interface) decl. *) (** If inside an objc class, contains the objc class (impl or interface) decl. *)
; current_objc_class: Clang_ast_t.decl option ; current_objc_class: Clang_ast_t.decl option
; et_evaluation_node: string option ; et_evaluation_node: string option
; if_context: if_context option } ; if_context: if_context option
; in_for_loop_declaration: bool }
val empty : CFrontend_config.translation_unit_context -> context val empty : CFrontend_config.translation_unit_context -> context

@ -126,6 +126,7 @@ let mutable_local_vars_advice context an =
is_ck_context context an && not (CAst_utils.is_syntactically_global_var decl) is_ck_context context an && not (CAst_utils.is_syntactically_global_var decl)
&& not (CAst_utils.is_static_local_var decl) && not is_const && not (CAst_utils.is_static_local_var decl) && not is_const
&& not (is_of_whitelisted_type qual_type) && not decl_info.di_is_implicit && not (is_of_whitelisted_type qual_type) && not decl_info.di_is_implicit
&& not context.CLintersContext.in_for_loop_declaration
in in
if condition then if condition then
Some Some

@ -241,10 +241,11 @@ let rec do_frontend_checks_stmt (context: CLintersContext.context)
(* distinguish between then and else branch as they need different context *) (* distinguish between then and else branch as they need different context *)
[ (context, [stmt1; stmt2; cond_stmt; inside_else_stmt]) [ (context, [stmt1; stmt2; cond_stmt; inside_else_stmt])
; (inside_if_stmt_context, [inside_if_stmt]) ] ; (inside_if_stmt_context, [inside_if_stmt]) ]
(* given that this has not been translated, looking up for variables *) | ForStmt (_, stmt1 :: stmts)
(* inside leads to inconsistencies *) -> let inside_for_stmt_decl_context =
| ObjCAtCatchStmt _ {context with CLintersContext.in_for_loop_declaration= true}
-> [(context, [])] in
[(context, stmts); (inside_for_stmt_decl_context, [stmt1])]
| _ | _
-> [(context, snd (Clang_ast_proj.get_stmt_tuple stmt))] -> [(context, snd (Clang_ast_proj.get_stmt_tuple stmt))]
in in

@ -16,6 +16,9 @@
@implementation SomeClass @implementation SomeClass
+ (instancetype) new { + (instancetype) new {
int i; // error int i; // error
for (int i = 0; i < 10; i++) {
}
return nil; return nil;
} }
@end @end

Loading…
Cancel
Save