From: nobu.nakada@... Date: 2002-09-13T14:23:42+09:00 Subject: [ruby-dev:18278] OP_ASGN_OR warning (Re: [ruby-cvs] ruby/lib, ruby: * lib/mkmf.rb ($INSTALLFILES): avoid warning when $VERBOSE mode.) なかだです。 At Fri, 13 Sep 2002 04:30:28 +0000, eban wrote: > Log: > * lib/mkmf.rb ($INSTALLFILES): avoid warning when $VERBOSE mode. これを見て気づいたんですが、未定義の変数に||=で代入したときに、 ローカル変数とインスタンス変数では警告が出ませんが、グローバル 変数では出ます。クラス変数はエラーになります。統一したほうがよ くないでしょうか。 $ ruby -ve ' local ||= 1 @instance ||= 1 $global ||= 1 @@class ||= 1 ' -e:4: warning: global variable `$global' not initialized -e:5: uninitialized class variable @@class in Object (NameError) ruby 1.7.3 (2002-09-12) [i686-linux] Index: eval.c =================================================================== RCS file: /cvs/ruby/src/ruby/eval.c,v retrieving revision 1.327 diff -u -2 -p -r1.327 eval.c --- eval.c 11 Sep 2002 15:13:10 -0000 1.327 +++ eval.c 13 Sep 2002 05:08:34 -0000 @@ -2892,5 +2892,5 @@ rb_eval(self, n) case NODE_OP_ASGN_OR: - if ((node->nd_aid && !rb_ivar_defined(self, node->nd_aid)) || + if ((node->nd_aid && !is_defined(self, node->nd_head, 0)) || !RTEST(result = rb_eval(self, node->nd_head))) { node = node->nd_value; Index: parse.y =================================================================== RCS file: /cvs/ruby/src/ruby/parse.y,v retrieving revision 1.214 diff -u -2 -p -r1.214 parse.y --- parse.y 10 Sep 2002 14:38:20 -0000 1.214 +++ parse.y 13 Sep 2002 05:17:03 -0000 @@ -50,4 +50,9 @@ #define is_class_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CLASS) +#define is_asgn_or_id(id) ((is_notop_id(id)) && \ + (((id)&ID_SCOPE_MASK) == ID_GLOBAL || \ + ((id)&ID_SCOPE_MASK) == ID_INSTANCE || \ + ((id)&ID_SCOPE_MASK) == ID_CLASS)) + NODE *ruby_eval_tree_begin = 0; NODE *ruby_eval_tree = 0; @@ -463,5 +468,5 @@ stmt : kALIAS fitem {lex_state = EXPR_F $1->nd_value = $3; $$ = NEW_OP_ASGN_OR(gettable(vid), $1); - if (is_instance_id(vid)) { + if (is_asgn_or_id(vid)) { $$->nd_aid = vid; } @@ -829,5 +834,5 @@ arg : lhs '=' arg $1->nd_value = $3; $$ = NEW_OP_ASGN_OR(gettable(vid), $1); - if (is_instance_id(vid)) { + if (is_asgn_or_id(vid)) { $$->nd_aid = vid; } -- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦