From 64ac984129a7a4645efe5ac57c168ef880b479b2 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 21 May 2021 11:01:06 -0700 Subject: Make RubyVM::AbstractSyntaxTree.of raise for method/proc created in eval This changes Thread::Location::Backtrace#absolute_path to return nil for methods/procs defined in eval. If the realpath of an iseq is nil, that indicates it was defined in eval, in which case you cannot use RubyVM::AbstractSyntaxTree.of. Fixes [Bug #16983] Co-authored-by: Koichi Sasada --- ast.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ast.c') diff --git a/ast.c b/ast.c index 32d8ab9eb6..20c4588cd7 100644 --- a/ast.c +++ b/ast.c @@ -213,6 +213,9 @@ ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE save_script else { iseq = rb_method_iseq(body); } + if (rb_iseq_from_eval_p(iseq)) { + rb_raise(rb_eArgError, "cannot get AST for method defined in eval"); + } path = rb_iseq_path(iseq); node_id = iseq->body->location.node_id; } -- cgit v1.2.1