summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2021-12-19 03:40:44 +0900
committerYusuke Endoh <mame@ruby-lang.org>2021-12-19 03:51:37 +0900
commitacac2b8128980b97c64b4d057acdf2ceffb0b981 (patch)
treebae29bfb63407ab9f9cccc3c57070ac99fdfe879 /ast.c
parent7e0e6f90744ec89a87554d209fb797ddf7919319 (diff)
downloadruby-acac2b8128980b97c64b4d057acdf2ceffb0b981.tar.gz
Make RubyVM::AbstractSyntaxTree.of raise for backtrace location in eval
This check is needed to fix a bug of error_highlight when NameError occurred in eval'ed code. https://github.com/ruby/error_highlight/pull/16 The same check for proc/method has been already introduced since 64ac984129a7a4645efe5ac57c168ef880b479b2.
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/ast.c b/ast.c
index 05bfc755a3..e180213ef7 100644
--- a/ast.c
+++ b/ast.c
@@ -196,14 +196,15 @@ static VALUE
ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script_lines)
{
VALUE path, node, lines = Qnil;
+ const rb_iseq_t *iseq;
int node_id;
if (rb_frame_info_p(body)) {
- rb_frame_info_get(body, &path, &lines, &node_id);
- if (NIL_P(path) && NIL_P(lines)) return Qnil;
+ iseq = rb_get_iseq_from_frame_info(body);
+ node_id = rb_get_node_id_from_frame_info(body);
}
else {
- const rb_iseq_t *iseq = NULL;
+ iseq = NULL;
if (rb_obj_is_proc(body)) {
iseq = vm_proc_iseq(body);
@@ -213,17 +214,20 @@ ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script
else {
iseq = rb_method_iseq(body);
}
- if (!iseq) {
- return Qnil;
+ if (iseq) {
+ node_id = iseq->body->location.node_id;
}
- if (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;
- node_id = iseq->body->location.node_id;
}
+ if (!iseq) {
+ return Qnil;
+ }
+ if (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);
}