From ecdf51dfc405ec0f9505caef7abb13be163cd926 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 17 Apr 2003 05:22:40 +0000 Subject: [PATCH] * parse.y (cond0): warn only range literals whose both side are literals. [ruby-core:00964] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ parse.y | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9bdf114c10..f895fd85b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Apr 17 14:22:36 2003 Nobuyoshi Nakada + + * parse.y (cond0): warn only range literals whose both side are + literals. [ruby-core:00964] + Thu Apr 17 11:10:59 2003 WATANABE Hirofumi * ext/readline/readline.c: add the defined operator for bcc32. diff --git a/parse.y b/parse.y index cae73c3e0c..a0bc7d2dec 100644 --- a/parse.y +++ b/parse.y @@ -5196,6 +5196,28 @@ range_op(node) return node; } +static int +literal_node(node) + NODE *node; +{ + if (!node) return 1; /* same as NODE_NIL */ + switch (nd_type(node)) { + case NODE_LIT: + case NODE_STR: + case NODE_DSTR: + case NODE_EVSTR: + case NODE_DREGX: + case NODE_DREGX_ONCE: + case NODE_DSYM: + return 2; + case NODE_TRUE: + case NODE_FALSE: + case NODE_NIL: + return 1; + } + return 0; +} + static NODE* cond0(node) NODE *node; @@ -5206,6 +5228,7 @@ cond0(node) switch (type) { case NODE_DSTR: + case NODE_EVSTR: case NODE_STR: rb_warn("string literal in condition"); break; @@ -5230,7 +5253,17 @@ cond0(node) if (type == NODE_DOT2) nd_set_type(node,NODE_FLIP2); else if (type == NODE_DOT3) nd_set_type(node, NODE_FLIP3); node->nd_cnt = local_append(internal_id()); - warning_unless_e_option("range literal in condition"); + if (!e_option_supplied()) { + int b = literal_node(node->nd_beg); + int e = literal_node(node->nd_end); + if ((b == 1 && e == 1) || (b + e >= 2 && RTEST(ruby_verbose))) { + rb_warn("range literal in condition"); + } + } + break; + + case NODE_DSYM: + rb_warning("literal in condition"); break; case NODE_LIT: