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

ruby-changes:45240

From: nobu <ko1@a...>
Date: Thu, 12 Jan 2017 16:41:42 +0900 (JST)
Subject: [ruby-changes:45240] nobu:r57313 (trunk): immediate message mode of compile error

nobu	2017-01-12 16:41:35 +0900 (Thu, 12 Jan 2017)

  New Revision: 57313

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

  Log:
    immediate message mode of compile error
    
    * compile.c (append_compile_error): set Qtrue for erred state with
      showing the message immediately.
    
    * iseq.c (prepare_iseq_build): make immediate message mode if main
      or top level context, not to show the failed path twice in the
      first line.
    
    * iseq.c (cleanup_iseq_build): raise default message exception if
      immediate message mode.

  Modified files:
    trunk/compile.c
    trunk/eval_error.c
    trunk/iseq.c
    trunk/test/ruby/test_syntax.rb
Index: compile.c
===================================================================
--- compile.c	(revision 57312)
+++ compile.c	(revision 57313)
@@ -337,7 +337,7 @@ append_compile_error(rb_iseq_t *iseq, in https://github.com/ruby/ruby/blob/trunk/compile.c#L337
 {
     VALUE err_info = ISEQ_COMPILE_DATA(iseq)->err_info;
     VALUE file = iseq->body->location.path;
-    VALUE err = err_info;
+    VALUE err = err_info == Qtrue ? Qfalse : err_info;
     va_list args;
 
     va_start(args, fmt);
@@ -347,6 +347,9 @@ append_compile_error(rb_iseq_t *iseq, in https://github.com/ruby/ruby/blob/trunk/compile.c#L347
 	RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->err_info, err);
 	rb_set_errinfo(err);
     }
+    else if (!err_info) {
+	RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->err_info, Qtrue);
+    }
 }
 
 static void
Index: eval_error.c
===================================================================
--- eval_error.c	(revision 57312)
+++ eval_error.c	(revision 57313)
@@ -294,7 +294,7 @@ error_handle(int ex) https://github.com/ruby/ruby/blob/trunk/eval_error.c#L294
 	    /* no message when exiting by signal */
 	}
 	else {
-	    error_print(th);
+	    rb_threadptr_error_print(th, errinfo);
 	}
 	break;
       }
Index: iseq.c
===================================================================
--- iseq.c	(revision 57312)
+++ iseq.c	(revision 57313)
@@ -272,6 +272,10 @@ prepare_iseq_build(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L272
 		   const rb_compile_option_t *option)
 {
     VALUE coverage = Qfalse;
+    VALUE err_info = Qnil;
+
+    if (parent && (type == ISEQ_TYPE_MAIN || type == ISEQ_TYPE_TOP))
+	err_info = Qfalse;
 
     iseq->body->type = type;
     set_relation(iseq, parent);
@@ -286,7 +290,7 @@ prepare_iseq_build(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L290
     RB_OBJ_WRITE(iseq, &iseq->body->mark_ary, iseq_mark_ary_create(0));
 
     ISEQ_COMPILE_DATA(iseq) = ZALLOC(struct iseq_compile_data);
-    RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->err_info, Qnil);
+    RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->err_info, err_info);
     RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->mark_ary, rb_ary_tmp_new(3));
 
     ISEQ_COMPILE_DATA(iseq)->storage_head = ISEQ_COMPILE_DATA(iseq)->storage_current =
@@ -325,6 +329,7 @@ cleanup_iseq_build(rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L329
     compile_data_free(data);
 
     if (RTEST(err)) {
+	if (err == Qtrue) err = rb_exc_new_cstr(rb_eSyntaxError, "compile error");
 	rb_funcallv(err, rb_intern("set_backtrace"), 1, &iseq->body->location.path);
 	rb_exc_raise(err);
     }
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 57312)
+++ test/ruby/test_syntax.rb	(revision 57313)
@@ -975,6 +975,10 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L975
     end;
   end
 
+  def test_invalid_jump
+    assert_in_out_err(%w[-e redo], "", [], /^-e:1: /)
+  end
+
   private
 
   def not_label(x) @result = x; @not_label ||= nil end

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

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