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

ruby-changes:68030

From: Yusuke <ko1@a...>
Date: Sat, 18 Sep 2021 21:29:52 +0900 (JST)
Subject: [ruby-changes:68030] ed9d9cee76 (master): ast.c: AST.of checks if a given method object is defined in C

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

From ed9d9cee76ee941c504ccea33c70c0eb5d825813 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Sat, 18 Sep 2021 21:28:35 +0900
Subject: ast.c: AST.of checks if a given method object is defined in C

[Bug #18178]
---
 ast.c                 | 3 +++
 test/ruby/test_ast.rb | 5 +++++
 2 files changed, 8 insertions(+)

diff --git a/ast.c b/ast.c
index 202527f..e1c044e 100644
--- a/ast.c
+++ b/ast.c
@@ -213,6 +213,9 @@ ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script https://github.com/ruby/ruby/blob/trunk/ast.c#L213
         else {
             iseq = rb_method_iseq(body);
         }
+        if (!iseq) {
+            rb_raise(rb_eArgError, "cannot get AST for method that is not defined in Ruby");
+        }
         if (rb_iseq_from_eval_p(iseq)) {
             rb_raise(rb_eArgError, "cannot get AST for method defined in eval");
         }
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb
index 3af67b1..0b5c410 100644
--- a/test/ruby/test_ast.rb
+++ b/test/ruby/test_ast.rb
@@ -231,6 +231,11 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L231
     assert_raise(ArgumentError) { RubyVM::AbstractSyntaxTree.of(method) }
   end
 
+  def test_of_c_method
+    c = Class.new { attr_reader :foo }
+    assert_raise(ArgumentError) { RubyVM::AbstractSyntaxTree.of(c.instance_method(:foo)) }
+  end
+
   def test_scope_local_variables
     node = RubyVM::AbstractSyntaxTree.parse("_x = 0")
     lv, _, body = *node.children
-- 
cgit v1.1


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

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