From 3d38c96f5f50aac80b7352b9d2129db93ecde002 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Mon, 26 May 2003 11:44:29 +0000 Subject: - warn things like: if ($a = 1) { ... } - undef is always false --- perl_checker.src/parser_helper.ml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index dd3428f..654999a 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -97,6 +97,7 @@ let is_always_false = function | Raw_string(s, _) -> s = "" | String(l, _) -> l = [] | List [] -> true + | Ident(None, "undef", _) -> true | _ -> false let not_complex e = @@ -606,6 +607,11 @@ let cook_call_op op para pos = let l = string_of_Ident l in warn_rule (sprintf "use \"push @%s, map { ... } ...\" instead of \"foreach (...) { push @%s, ... }\"\n or sometimes \"@%s = map { ... } ...\"" l l l) | _ -> ()) + | "if" -> + (match para with + | List [Call_op ("=", [ _; e ], _)] :: _ when is_always_true e || is_always_false e -> + warn_rule "are you sure you did not mean \"==\" instead of \"=\"?" + | _ -> ()) | _ -> ()); let call = Call_op(op, para, raw_pos2pos pos) in match op, para with -- cgit v1.2.1