summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2024-02-14 10:58:20 -0500
committerKevin Newton <[email protected]>2024-02-21 11:44:40 -0500
commit82a4c3af1629298524024494fd065d51ff6ad5c6 (patch)
tree6df3953e4872979dc4e90b31505a79e34ed66ae4
parent0f1ca9492c63bc2e59b61c4d9b7e253e31af494d (diff)
Add error for iseqs compiled by prism
-rw-r--r--ast.c5
-rw-r--r--lib/error_highlight/base.rb11
2 files changed, 15 insertions, 1 deletions
diff --git a/ast.c b/ast.c
index 3b0b53e64e..66e237b1f2 100644
--- a/ast.c
+++ b/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);
diff --git a/lib/error_highlight/base.rb b/lib/error_highlight/base.rb
index 7d2ff0c889..b9c68b8eb8 100644
--- a/lib/error_highlight/base.rb
+++ b/lib/error_highlight/base.rb
@@ -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