summaryrefslogtreecommitdiffstats
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
commit3d38c96f5f50aac80b7352b9d2129db93ecde002 (patch)
treec53b386f3a60838ca439e6078e95879ab8c02217
parent0d99c9e73026839ce4a7dfc4617cf7df22aef64c (diff)
downloadperl_checker-3d38c96f5f50aac80b7352b9d2129db93ecde002.tar
perl_checker-3d38c96f5f50aac80b7352b9d2129db93ecde002.tar.gz
perl_checker-3d38c96f5f50aac80b7352b9d2129db93ecde002.tar.bz2
perl_checker-3d38c96f5f50aac80b7352b9d2129db93ecde002.tar.xz
perl_checker-3d38c96f5f50aac80b7352b9d2129db93ecde002.zip
- warn things like: if ($a = 1) { ... }
- undef is always false
-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