Add error for iseqs compiled by prism

This commit is contained in:
Kevin Newton 2024-02-14 10:58:20 -05:00
Родитель 0f1ca9492c
Коммит 82a4c3af16
2 изменённых файлов: 15 добавлений и 1 удалений

5
ast.c
Просмотреть файл

@ -253,6 +253,11 @@ ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script
if (!iseq) {
return Qnil;
}
if (ISEQ_BODY(iseq)->prism) {
rb_raise(rb_eRuntimeError, "cannot get AST for ISEQ compiled by prism");
}
lines = ISEQ_BODY(iseq)->variable.script_lines;
VALUE path = rb_iseq_path(iseq);

Просмотреть файл

@ -54,7 +54,16 @@ module ErrorHighlight
return nil unless Thread::Backtrace::Location === loc
node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true)
node =
begin
RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true)
rescue RuntimeError => error
# RubyVM::AbstractSyntaxTree.of raises an error with a message that
# includes "prism" when the ISEQ was compiled with the prism compiler.
# In this case, we'll set the node to `nil`. In the future, we will
# reparse with the prism parser and pass the parsed node to Spotter.
raise unless error.message.include?("prism")
end
Spotter.new(node, **opts).spot