[#1551] Hashes as keys — "Nathaniel Talbott" <nathaniel@...>

I was just playing around with Hash#hash and discovered that you can't use a

13 messages 2003/09/23

Assignment to $--, $- and the like

From: Mauricio Fern疣dez <batsman.geo@...>
Date: 2003-09-06 15:14:47 UTC
List: ruby-core #1523
------- [Forwarded From: Florian Gross <flgr@ccan.de>] ------- 

Moin!

Compare this:
   ruby -e "$--"
   -e:1: identifier $-- is not valid
to this:
   ruby -e "$-- = 1"
   -e:1: [BUG] bad id for variable
   ruby 1.8.0 (2003-08-04) [i386-mswin32]

And this:
   ruby -e "$-"
   -e:1: identifier $-
    is not valid
to this:
   ruby -e "$- = 1"
   -e:1: [BUG] bad id for variable
   ruby 1.8.0 (2003-08-04) [i386-mswin32]

IMHO assigning to a global variable with such an illegal name shouldn't 
cause the parser to abort -- instead it should report the same error you 
get when trying to use the value of such an invalid global variable.

Patch that changes the current behaviour to the one I suggested:

--- parse.y  2003-09-06 11:41:46.769651200 +0200
+++ parse.y  2003-09-06 11:45:59.081491200 +0200
@@ -4856,7 +4856,7 @@
        return NEW_CVDECL(id, val);
      }
      else {
-      rb_bug("bad id for variable");
+      rb_compile_error("identifier %s is not valid", rb_id2name(id));
      }
      return 0;
  }

Regards,
Florian Gross


In This Thread

Prev Next