[前][次][番号順一覧][スレッド一覧]

ruby-changes:47592

From: nobu <ko1@a...>
Date: Fri, 1 Sep 2017 09:43:05 +0900 (JST)
Subject: [ruby-changes:47592] nobu:r59708 (trunk): compile.c: ensure after toplevel return

nobu	2017-09-01 09:43:00 +0900 (Fri, 01 Sep 2017)

  New Revision: 59708

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59708

  Log:
    compile.c: ensure after toplevel return
    
    * compile.c (iseq_compile_each0): toplevel returns should fire
      ensures.  [ruby-core:82492] [Bug #13844]

  Modified files:
    trunk/compile.c
    trunk/test/ruby/test_syntax.rb
Index: compile.c
===================================================================
--- compile.c	(revision 59707)
+++ compile.c	(revision 59708)
@@ -5771,7 +5771,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5771
 	    const rb_iseq_t *parent_iseq = is->body->parent_iseq;
 	    enum iseq_type parent_type;
 
-	    if (type == ISEQ_TYPE_TOP || type == ISEQ_TYPE_MAIN) {
+	    if (type == ISEQ_TYPE_TOP) {
 		LABEL *splabel = NEW_LABEL(line);
 		ADD_LABEL(ret, splabel);
 		ADD_ADJUST(ret, line, 0);
@@ -5779,7 +5779,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5779
 		ADD_INSN(ret, line, leave);
 		ADD_ADJUST_RESTORE(ret, splabel);
 	    }
-	    else if ((type == ISEQ_TYPE_RESCUE || type == ISEQ_TYPE_ENSURE) &&
+	    else if ((type == ISEQ_TYPE_RESCUE || type == ISEQ_TYPE_ENSURE || type == ISEQ_TYPE_MAIN) &&
 		     parent_iseq &&
 		     ((parent_type = parent_iseq->body->type) == ISEQ_TYPE_TOP ||
 		      parent_type == ISEQ_TYPE_MAIN)) {
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 59707)
+++ test/ruby/test_syntax.rb	(revision 59708)
@@ -986,7 +986,7 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L986
     begin;
       return; raise
       begin return; rescue SystemExit; exit false; end
-      begin return; ensure exit false; end
+      begin return; ensure puts "ensured"; end #=> ensured
       begin ensure return; end
       begin raise; ensure; return; end
       begin raise; rescue; return; end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]