summaryrefslogtreecommitdiffstats
path: root/perl_checker.src/parser_helper.ml
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-05-26 11:44:29 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-05-26 11:44:29 +0000
commitfdb0bdb253df87dbe4942d4d5afcc687bda6b366 (patch)
tree00b5780633f486505466250d87c69c18d59de09a /perl_checker.src/parser_helper.ml
parent433c1f2dd33b0631ff956bc73a15cd85f8c34f50 (diff)
downloadperl-MDK-Common-fdb0bdb253df87dbe4942d4d5afcc687bda6b366.tar
perl-MDK-Common-fdb0bdb253df87dbe4942d4d5afcc687bda6b366.tar.gz
perl-MDK-Common-fdb0bdb253df87dbe4942d4d5afcc687bda6b366.tar.bz2
perl-MDK-Common-fdb0bdb253df87dbe4942d4d5afcc687bda6b366.tar.xz
perl-MDK-Common-fdb0bdb253df87dbe4942d4d5afcc687bda6b366.zip
- warn things like: if ($a = 1) { ... }
- undef is always false
Diffstat (limited to 'perl_checker.src/parser_helper.ml')
-rw-r--r--perl_checker.src/parser_helper.ml6
1 files changed, 6 insertions, 0 deletions
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