Hi,

At Thu, 17 Apr 2003 11:50:17 +0900,
Yukihiro Matsumoto wrote:
> |> I assumed that was referring to stuff with an implicit $_ or $., such as
> |> 
> |>    print if 10..20
> |> 
> |> or
> |> 
> |>    print if /cat/../dog/
> |> 
> |> I'm not sure I see the reason for deprecating the more general form.
> |
> |Exactly.  And some new nodes are not warned.
> 
> Oops, could you commit this fix?

More thoughts about builtin literals, i.e., true/false/nil.

* if both sides are them, the range is meaningless.
    print if true..false		# should be warned always.

* just one side, however, may make sense.
    print if (/cat/ =~ line)..true	# print lines from "cat" through EOF.

* bare regexps and numerics should be warned, of course.
    print if /cat/..true		# same as above, but warning.


Index: parse.y =================================================================== RCS file: /pub/cvs/ruby/src/ruby/parse.y,v retrieving revision 1.268 diff -u -2 -p -r1.268 parse.y --- parse.y 10 Apr 2003 08:37:12 -0000 1.268 +++ parse.y 17 Apr 2003 02:52:45 -0000 @@ -5197,4 +5197,26 @@ range_op(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) @@ -5207,4 +5229,5 @@ cond0(node) switch (type) { case NODE_DSTR: + case NODE_EVSTR: case NODE_STR: rb_warn("string literal in condition"); @@ -5231,5 +5254,15 @@ cond0(node) 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;
-- Nobu Nakada