summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-03-28 10:07:04 -0400
committerKevin Newton <kddnewton@gmail.com>2024-03-28 12:04:35 -0400
commitf7c5e11d894c6c6a965a9fa98ff9519635b6db2b (patch)
tree5fceee69177362f0842ddad745ebb1d4d80ee968
parentfcc06fa82ab6f3916d8d9202c47db4fae48137dd (diff)
[PRISM] Use new -x prism API
-rw-r--r--prism_compile.c27
-rw-r--r--spec/prism.mspec4
2 files changed, 21 insertions, 10 deletions
diff --git a/prism_compile.c b/prism_compile.c
index 6e27d01729..5a5b1e7d61 100644
--- a/prism_compile.c
+++ b/prism_compile.c
@@ -8390,10 +8390,11 @@ pm_parse_process_error(const pm_parse_result_t *result)
const pm_string_t *filepath = &parser->filepath;
for (const pm_diagnostic_t *error = head; error != NULL; error = (const pm_diagnostic_t *) error->node.next) {
- // Any errors with the level PM_ERROR_LEVEL_ARGUMENT effectively take
- // over as the only argument that gets raised. This is to allow priority
- // messages that should be handled before anything else.
- if (error->level == PM_ERROR_LEVEL_ARGUMENT) {
+ // Any errors with the level that is not PM_ERROR_LEVEL_SYNTAX
+ // effectively take over as the only argument that gets raised. This is
+ // to allow priority messages that should be handled before anything
+ // else.
+ if (error->level != PM_ERROR_LEVEL_SYNTAX) {
int32_t line_number = (int32_t) pm_location_line_number(parser, &error->location);
pm_buffer_append_format(
@@ -8414,10 +8415,24 @@ pm_parse_process_error(const pm_parse_result_t *result)
pm_parser_errors_format(parser, &error_list, &buffer, rb_stderr_tty_p(), false);
}
- VALUE arg_error = rb_exc_new(rb_eArgError, pm_buffer_value(&buffer), pm_buffer_length(&buffer));
+ VALUE class;
+ switch (error->level) {
+ case PM_ERROR_LEVEL_ARGUMENT:
+ class = rb_eArgError;
+ break;
+ case PM_ERROR_LEVEL_LOAD:
+ class = rb_eLoadError;
+ break;
+ default:
+ class = rb_eSyntaxError;
+ RUBY_ASSERT(false && "unexpected error level");
+ break;
+ }
+
+ VALUE value = rb_exc_new(class, pm_buffer_value(&buffer), pm_buffer_length(&buffer));
pm_buffer_free(&buffer);
- return arg_error;
+ return value;
}
// It is implicitly assumed that the error messages will be encodeable
diff --git a/spec/prism.mspec b/spec/prism.mspec
index 252432c943..dd499dbc29 100644
--- a/spec/prism.mspec
+++ b/spec/prism.mspec
@@ -1,10 +1,6 @@
# frozen_string_literal: true
## Command line
-MSpec.register(:exclude, "The -S command line option runs launcher found in PATH, but only code after the first /#!.*ruby.*/-ish line in target file")
-MSpec.register(:exclude, "The -x command line option runs code after the first /#!.*ruby.*/-ish line in target file")
-MSpec.register(:exclude, "The -x command line option fails when /#!.*ruby.*/-ish line in target file is not found")
-MSpec.register(:exclude, "The -x command line option behaves as -x was set when non-ruby shebang is encountered on first line")
MSpec.register(:exclude, "The --debug flag produces debugging info on attempted frozen string modification")
## Language