summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2021-12-19 04:00:51 +0900
committerYusuke Endoh <mame@ruby-lang.org>2021-12-19 04:00:51 +0900
commit6a51c3e80c0901851c252ed4d1387e43939a452f (patch)
tree407baa63ca98192826df2fce979fa2e840cfd7db /ast.c
parentacac2b8128980b97c64b4d057acdf2ceffb0b981 (diff)
Make AST.of possible even under eval when keep_script_lines is enabled
Now the following code works without an exception. ``` RubyVM.keep_script_lines = true eval(<<END) def foo end END p RubyVM::AbstractSyntaxTree.of(method(:foo)) ```
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/ast.c b/ast.c
index e180213ef7..466e7a6a2e 100644
--- a/ast.c
+++ b/ast.c
@@ -222,11 +222,11 @@ ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script
if (!iseq) {
return Qnil;
}
- if (rb_iseq_from_eval_p(iseq)) {
+ lines = iseq->body->variable.script_lines;
+ if (NIL_P(lines) && rb_iseq_from_eval_p(iseq)) {
rb_raise(rb_eArgError, "cannot get AST for method defined in eval");
}
path = rb_iseq_path(iseq);
- lines = iseq->body->variable.script_lines;
if (!NIL_P(lines) || !NIL_P(lines = script_lines(path))) {
node = rb_ast_parse_array(lines, keep_script_lines);