diff --git a/ChangeLog b/ChangeLog index 344962a89a..3155dfe855 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Wed Apr 20 10:25:53 2016 Nobuyoshi Nakada + + * compile.c (append_compile_error): use rb_syntax_error_append. + + * error.c (rb_syntax_error_append): append messages into a + SyntaxError exception instance. + + * parse.y (yycompile0): make new SyntaxError instance in main + mode, otherwize error_buffer should be a SyntaxError if error + has occurred. + Tue Apr 19 17:42:47 2016 Nobuyoshi Nakada * error.c (err_vcatf): rename, and separate appending message from diff --git a/compile.c b/compile.c index 0f319b7ce8..63be63c13d 100644 --- a/compile.c +++ b/compile.c @@ -318,18 +318,11 @@ static void append_compile_error(rb_iseq_t *iseq, int line, const char *fmt, ...) { VALUE err_info = ISEQ_COMPILE_DATA(iseq)->err_info; - VALUE str = rb_attr_get(err_info, idMesg); VALUE file = iseq->body->location.path; va_list args; - if (RSTRING_LEN(str)) rb_str_cat2(str, "\n"); - if (file) { - rb_str_concat(str, file); - if (line) rb_str_catf(str, ":%d", line); - rb_str_cat2(str, ": "); - } va_start(args, fmt); - rb_str_vcatf(str, fmt, args); + rb_syntax_error_append(err_info, file, line, -1, NULL, fmt, args); va_end(args); } diff --git a/error.c b/error.c index 6a8111085a..89858719c1 100644 --- a/error.c +++ b/error.c @@ -104,12 +104,18 @@ rb_syntax_error_append(VALUE exc, VALUE file, int line, int column, rb_str_cat2(mesg, "\n"); rb_write_error_str(mesg); } - else if (NIL_P(exc)) { - VALUE mesg = rb_enc_str_new(0, 0, enc); - exc = err_vcatf(mesg, NULL, fn, line, fmt, args); - } else { - err_vcatf(exc, "\n", fn, line, fmt, args); + VALUE mesg; + const char *pre = NULL; + if (NIL_P(exc)) { + mesg = rb_enc_str_new(0, 0, enc); + exc = rb_class_new_instance(1, &mesg, rb_eSyntaxError); + } + else { + mesg = rb_attr_get(exc, idMesg); + pre = "\n"; + } + err_vcatf(mesg, pre, fn, line, fmt, args); } return exc; diff --git a/internal.h b/internal.h index 126410796e..f3767110cc 100644 --- a/internal.h +++ b/internal.h @@ -852,6 +852,7 @@ extern VALUE rb_eEWOULDBLOCK; extern VALUE rb_eEINPROGRESS; void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args); PRINTF_ARGS(void rb_compile_error_str(VALUE file, int line, void *enc, const char *fmt, ...), 4, 5); +VALUE rb_syntax_error_append(VALUE, VALUE, int, int, rb_encoding*, const char*, va_list); VALUE rb_check_backtrace(VALUE); NORETURN(void rb_async_bug_errno(const char *,int)); const char *rb_builtin_type_name(int t); diff --git a/parse.y b/parse.y index 2243f69765..56f4d837c5 100644 --- a/parse.y +++ b/parse.y @@ -5550,8 +5550,11 @@ yycompile0(VALUE arg) lex_lastline = lex_nextline = 0; if (parser->error_p) { VALUE mesg = parser->error_buffer; - if (!mesg) mesg = rb_fstring_cstr("compile error"); - rb_set_errinfo(rb_exc_new_str(rb_eSyntaxError, mesg)); + if (!mesg) { + mesg = rb_fstring_cstr("compile error"); + mesg = rb_exc_new_str(rb_eSyntaxError, mesg); + } + rb_set_errinfo(mesg); return 0; } tree = ruby_eval_tree; @@ -11074,8 +11077,6 @@ rb_parser_printf(struct parser_params *parser, const char *fmt, ...) } } -extern VALUE rb_syntax_error_append(VALUE exc, VALUE file, int line, int column, rb_encoding *enc, const char *fmt, va_list args); - static void parser_compile_error(struct parser_params *parser, const char *fmt, ...) {