summaryrefslogtreecommitdiffstats
path: root/perl_checker.src
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-04-10 19:29:19 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-04-10 19:29:19 +0000
commit6dc2e6b91b88b11cb1dde2ddd1a5dee6e7d3495e (patch)
tree5c80ea5d681c7c55e7d1b0f356a6907ca4700df1 /perl_checker.src
parent3c2420fe71cc4c1d5c0c3edcc174fae7063da2d6 (diff)
downloadperl-MDK-Common-6dc2e6b91b88b11cb1dde2ddd1a5dee6e7d3495e.tar
perl-MDK-Common-6dc2e6b91b88b11cb1dde2ddd1a5dee6e7d3495e.tar.gz
perl-MDK-Common-6dc2e6b91b88b11cb1dde2ddd1a5dee6e7d3495e.tar.bz2
perl-MDK-Common-6dc2e6b91b88b11cb1dde2ddd1a5dee6e7d3495e.tar.xz
perl-MDK-Common-6dc2e6b91b88b11cb1dde2ddd1a5dee6e7d3495e.zip
enhance non_scalar case for some operators using is_not_a_scalar
Diffstat (limited to 'perl_checker.src')
-rw-r--r--perl_checker.src/parser_helper.ml30
1 files changed, 20 insertions, 10 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 9b5269f..1ddeebc 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -33,6 +33,15 @@ let is_scalar_context context = context = I_scalar
let is_not_a_scalar = function
| Deref_with(_, context, _, _)
| Deref(context, _) -> non_scalar_context context
+ | List []
+ | List(_ :: _ :: _) -> true
+ | _ -> false
+
+let is_not_a_scalar_or_array = function
+ | Deref_with(_, context, _, _)
+ | Deref(context, _) -> context = I_hash
+ | List []
+ | List(_ :: _ :: _) -> true
| _ -> false
let is_a_scalar = function
@@ -44,6 +53,10 @@ let is_a_scalar = function
| Deref(context, _) -> is_scalar_context context
| _ -> false
+let is_a_string = function
+ | String _ | Raw_string _ -> true
+ | _ -> false
+
let is_parenthesized = function
| List[]
| List[List _] -> true
@@ -562,19 +575,16 @@ let cook_call_op(op, para, pos) =
let call_op_((prio, (prev_ter, op)), ter, para) (sp, pos) =
(match op with
- | "==" | "!=" ->
- if List.exists (function Undef | List(_ :: _ :: _) -> true | _ -> false) para then
- warn_rule "don't do this"
- else if List.exists (function String _ | Raw_string _ -> true | _ -> false) para then
- warn_rule (sprintf "you should use a string operator, not the number operator \"%s\"" op)
- | "<=" | ">=" | ">" | "<" | "<=>" ->
- if List.exists (function Undef | List [] | List(_ :: _ :: _) -> true | _ -> false) para then
- (* nb: allowing @l == () *)
+ | "==" | "!=" | "<=" | ">=" | ">" | "<" | "<=>" ->
+ if List.exists (function
+ | Undef
+ | List [] -> op <> "==" && op <> "!=" (* allowing @l == () *)
+ | e -> is_not_a_scalar_or_array e) para then
warn_rule "don't do this"
- else if List.exists (function String _ | Raw_string _ -> true | _ -> false) para then
+ else if List.exists is_a_string para then
warn_rule (sprintf "you should use a string operator, not the number operator \"%s\"" op)
| "le" | "ge" | "eq" | "ne" | "gt" | "lt" | "cmp" ->
- if List.exists (function Undef | List [] | List(_ :: _ :: _) -> true | _ -> false) para then
+ if List.exists is_not_a_scalar para then
warn_rule "don't do this"
else if List.exists (function Num _ -> true | _ -> false) para then
warn_rule (sprintf "you should use a number operator, not the string operator \"%s\" (or replace the number with a string)" op)