iseq.c: Make ast_line_count return 0 when syntax error occurred

This broke coverage CI

```
  1) Failure:
TestRequire#test_load_syntax_error [/home/runner/work/actions/actions/ruby/test/ruby/test_require.rb:228]:
Exception(SyntaxError) with message matches to /unexpected/.
[SyntaxError] exception expected, not #<TypeError: no implicit conversion of false into Integer>.
```
https://github.com/ruby/actions/runs/2914743968?check_suite_focus=true
This commit is contained in:
Yusuke Endoh 2021-06-26 00:13:47 +09:00
Родитель 5ffb313ccc
Коммит 68e1dc5172
1 изменённых файлов: 4 добавлений и 0 удалений

4
iseq.c
Просмотреть файл

@ -816,6 +816,10 @@ rb_iseq_new(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath,
static int static int
ast_line_count(const rb_ast_body_t *ast) ast_line_count(const rb_ast_body_t *ast)
{ {
if (ast->script_lines == Qfalse) {
// this occurs when failed to parse the source code with a syntax error
return 0;
}
if (RB_TYPE_P(ast->script_lines, T_ARRAY)){ if (RB_TYPE_P(ast->script_lines, T_ARRAY)){
return (int)RARRAY_LEN(ast->script_lines); return (int)RARRAY_LEN(ast->script_lines);
} }