ast.c: AST.of checks if a given method object is defined in C
[Bug #18178]
This commit is contained in:
parent
1c07c98229
commit
ed9d9cee76
3
ast.c
3
ast.c
@ -213,6 +213,9 @@ ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script
|
|||||||
else {
|
else {
|
||||||
iseq = rb_method_iseq(body);
|
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)) {
|
if (rb_iseq_from_eval_p(iseq)) {
|
||||||
rb_raise(rb_eArgError, "cannot get AST for method defined in eval");
|
rb_raise(rb_eArgError, "cannot get AST for method defined in eval");
|
||||||
}
|
}
|
||||||
|
@ -231,6 +231,11 @@ class TestAst < Test::Unit::TestCase
|
|||||||
assert_raise(ArgumentError) { RubyVM::AbstractSyntaxTree.of(method) }
|
assert_raise(ArgumentError) { RubyVM::AbstractSyntaxTree.of(method) }
|
||||||
end
|
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
|
def test_scope_local_variables
|
||||||
node = RubyVM::AbstractSyntaxTree.parse("_x = 0")
|
node = RubyVM::AbstractSyntaxTree.parse("_x = 0")
|
||||||
lv, _, body = *node.children
|
lv, _, body = *node.children
|
||||||
|
Loading…
x
Reference in New Issue
Block a user