From: "akira yamada / やまだあきら" Date: 2003-10-05T00:18:47+09:00 Subject: [ruby-dev:21486] Re: begin/rescue/else syntax is broken >>>>> In [ruby-dev : No.21482] >>>>> akira yamada wrote: > > で報告されているように、以下のコードではrescue節の後で > else節まで実行されてしまいます。 > > $ ./ruby -ve ' > begin > raise > rescue > p :OK > else > p :NG > end > ' > ruby 1.8.0 (2003-10-04) [i686-linux] > :OK > :NG こういう感じでどうでしょう? make testとtest/ruby/*はパスしています。 Index: eval.c =================================================================== RCS file: /src/ruby/eval.c,v retrieving revision 1.546 diff -u -r1.546 eval.c --- eval.c 2 Oct 2003 08:24:45 -0000 1.546 +++ eval.c 4 Oct 2003 15:16:59 -0000 @@ -2795,6 +2795,10 @@ PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { result = rb_eval(self, node->nd_head); + /* no exception raised */ + if (node = node->nd_else) { /* else clause given */ + goto again; + } } else if (rescuing) { if (rescuing < 0) { @@ -2827,10 +2831,6 @@ } POP_TAG(); if (state) JUMP_TAG(state); - /* no exception raised */ - if (node = node->nd_else) { /* else clause given */ - goto again; - } } break; Index: test/ruby/test_exception.rb =================================================================== RCS file: /src/ruby/test/ruby/test_exception.rb,v retrieving revision 1.2 diff -u -r1.2 test_exception.rb --- test/ruby/test_exception.rb 5 Sep 2003 15:15:43 -0000 1.2 +++ test/ruby/test_exception.rb 4 Oct 2003 15:16:59 -0000 @@ -94,4 +94,21 @@ }) end + + def test_else + begin + rescue + assert(false) + else + assert(true) + end + + begin + raise + rescue + assert(true) + else + assert(false) + end + end end -- やまだあきら / akira yamada Vine Caves, Ltd. (akira@arika.org, akira@debian.org or akira@vinecaves.com)