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

ruby-changes:66603

From: Yusuke <ko1@a...>
Date: Sat, 26 Jun 2021 00:15:37 +0900 (JST)
Subject: [ruby-changes:66603] 68e1dc5172 (master): iseq.c: Make ast_line_count return 0 when syntax error occurred

https://git.ruby-lang.org/ruby.git/commit/?id=68e1dc5172

From 68e1dc51720b0f8bb033aac368122dad6c9aa2ed Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Sat, 26 Jun 2021 00:13:47 +0900
Subject: 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
---
 iseq.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/iseq.c b/iseq.c
index 7a3d946..9af7b54 100644
--- a/iseq.c
+++ b/iseq.c
@@ -816,6 +816,10 @@ rb_iseq_new(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, https://github.com/ruby/ruby/blob/trunk/iseq.c#L816
 static int
 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)){
         return (int)RARRAY_LEN(ast->script_lines);
     }
-- 
cgit v1.1


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

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