summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-02-14 10:39:00 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-02-14 10:39:00 +0000
commitcd1285dd789ba84b526ade6c4f1e5d77c49a32a9 (patch)
treedd96bf139f0015d308e167c26bdf8dc09d6c28c2
parentc546ae4661be1e051df636a8b326ffabc8611201 (diff)
downloadperl-MDK-Common-cd1285dd789ba84b526ade6c4f1e5d77c49a32a9.tar
perl-MDK-Common-cd1285dd789ba84b526ade6c4f1e5d77c49a32a9.tar.gz
perl-MDK-Common-cd1285dd789ba84b526ade6c4f1e5d77c49a32a9.tar.bz2
perl-MDK-Common-cd1285dd789ba84b526ade6c4f1e5d77c49a32a9.tar.xz
perl-MDK-Common-cd1285dd789ba84b526ade6c4f1e5d77c49a32a9.zip
don't suggest to replace "@foo ? @foo : @bar" with "@foo || @bar", this is wrong!
-rw-r--r--perl-MDK-Common.spec5
-rw-r--r--perl_checker.src/parser_helper.ml26
2 files changed, 22 insertions, 9 deletions
diff --git a/perl-MDK-Common.spec b/perl-MDK-Common.spec
index 7f90c7e..15e4ec1 100644
--- a/perl-MDK-Common.spec
+++ b/perl-MDK-Common.spec
@@ -2,7 +2,7 @@
# do not change the version here, change in MDK/Common.pm.pl
%define version THEVERSION
-%define release 20mdk
+%define release 21mdk
Summary: Various simple functions
Name: perl-MDK-Common
@@ -51,6 +51,9 @@ rm -rf $RPM_BUILD_ROOT
# MODIFY IN THE CVS: cvs.mandrakesoft.com:/cooker soft/perl-MDK-Common
%changelog
+* Fri Feb 14 2003 Pixel <pixel@mandrakesoft.com> 1.0.4-21mdk
+- don't suggest to replace "@foo ? @foo : @bar" with "@foo || @bar", this is wrong!
+
* Thu Feb 13 2003 Pixel <pixel@mandrakesoft.com> 1.0.4-20mdk
- add some more Gtk2 methods
- check use of variables with name _XXX (reserved for unused variables)
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 2682bfb..edd0023 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -27,6 +27,23 @@ let is_var_number_match = function
| Deref(I_scalar, Ident(None, s, _)) -> String.length s = 1 && s.[0] <> '0' && char_is_number s.[0]
| _ -> false
+let non_scalar_context context = context = I_hash || context = I_array
+let is_scalar_context context = context = I_scalar
+
+let is_not_a_scalar = function
+ | Deref_with(_, context, _, _)
+ | Deref(context, _) -> non_scalar_context context
+ | _ -> false
+
+let is_a_scalar = function
+ | Ref _
+ | Num _
+ | Raw_string _
+ | String _ -> true
+ | Deref_with(_, context, _, _)
+ | Deref(context, _) -> is_scalar_context context
+ | _ -> false
+
let is_parenthesized = function
| List[]
| List[List _] -> true
@@ -66,8 +83,6 @@ let context2s = function
| I_star -> "*"
let variable2s(context, ident) = context2s context ^ ident
-let non_scalar_context context = context = I_hash || context = I_array
-
let rec is_same_fromparser a b =
match a, b with
| Undef, Undef -> true
@@ -329,7 +344,7 @@ let check_ternary_paras(cond, a, b) =
in
if dont_need_short_circuit a || is_same_fromparser cond a then check_ternary_para b;
if dont_need_short_circuit b || is_same_fromparser cond b then check_ternary_para a;
- if is_same_fromparser cond a && dont_need_short_circuit b then warn_rule "you can replace \"$foo ? $foo : $bar\" with \"$foo || $bar\"";
+ if is_same_fromparser cond a && dont_need_short_circuit b && is_a_scalar a && is_a_scalar b then warn_rule "you can replace \"$foo ? $foo : $bar\" with \"$foo || $bar\"";
[ cond; a; b ]
let check_unneeded_var_dollar_ ((_, e), (_, pos)) =
@@ -401,11 +416,6 @@ let rec is_only_one_in_List = function
| [List l] -> is_only_one_in_List l
| [_] -> true
| _ -> false
-
-let is_not_a_scalar = function
- | Deref_with(_, context, _, _)
- | Deref(context, _) -> non_scalar_context context
- | _ -> false
let maybe_to_Raw_string = function
| Ident(None, s, pos) -> Raw_string(s, pos)