diff options
-rw-r--r-- | compile.c | 5 | ||||
-rw-r--r-- | eval_error.c | 2 | ||||
-rw-r--r-- | iseq.c | 7 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 4 |
4 files changed, 15 insertions, 3 deletions
@@ -337,7 +337,7 @@ append_compile_error(rb_iseq_t *iseq, int line, const char *fmt, ...) { 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, int line, const char *fmt, ...) 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 diff --git a/eval_error.c b/eval_error.c index ff3db23a6b..b6f680748c 100644 --- a/eval_error.c +++ b/eval_error.c @@ -294,7 +294,7 @@ error_handle(int ex) /* no message when exiting by signal */ } else { - error_print(th); + rb_threadptr_error_print(th, errinfo); } break; } @@ -272,6 +272,10 @@ prepare_iseq_build(rb_iseq_t *iseq, 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, 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) 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); } diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 61aab4bee5..0f927a328e 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -975,6 +975,10 @@ eom 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 |