summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-27 15:49:09 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-27 15:49:09 +0000
commite672994d146eeb85fc3670cbd97b484f6101d373 (patch)
treef487f8442544a9ea907830bebba14f9460dae3ea /parse.y
parent1fe5783104b248be54f21d147722ca2ebc7d149a (diff)
parse.y: warn static content assign in cond
* parse.y (assign_in_cond): warn for static content object asignments in conditional statements. [ruby-dev:43083] [Feature #4299] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37344 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y40
1 files changed, 25 insertions, 15 deletions
diff --git a/parse.y b/parse.y
index ac3ec3aca3..5f3617556b 100644
--- a/parse.y
+++ b/parse.y
@@ -8936,6 +8936,30 @@ reduce_nodes_gen(struct parser_params *parser, NODE **body)
}
static int
+is_static_content(NODE *node)
+{
+ if (!node) return 1;
+ switch (nd_type(node)) {
+ case NODE_HASH:
+ if (!(node = node->nd_head)) break;
+ case NODE_ARRAY:
+ do {
+ if (!is_static_content(node->nd_head)) return 0;
+ } while ((node = node->nd_next) != 0);
+ case NODE_LIT:
+ case NODE_STR:
+ case NODE_NIL:
+ case NODE_TRUE:
+ case NODE_FALSE:
+ case NODE_ZARRAY:
+ break;
+ default:
+ return 0;
+ }
+ return 1;
+}
+
+static int
assign_in_cond(struct parser_params *parser, NODE *node)
{
switch (nd_type(node)) {
@@ -8955,23 +8979,9 @@ assign_in_cond(struct parser_params *parser, NODE *node)
}
if (!node->nd_value) return 1;
- switch (nd_type(node->nd_value)) {
- case NODE_LIT:
- case NODE_STR:
- case NODE_NIL:
- case NODE_TRUE:
- case NODE_FALSE:
+ if (is_static_content(node->nd_value)) {
/* reports always */
parser_warn(node->nd_value, "found = in conditional, should be ==");
- return 1;
-
- case NODE_DSTR:
- case NODE_XSTR:
- case NODE_DXSTR:
- case NODE_EVSTR:
- case NODE_DREGX:
- default:
- break;
}
return 1;
}