Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -19685,6 +19685,15 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, u
PM_PARSER_ERR_TOKEN_FORMAT(parser, &next, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_str(next.type));
}
}

// It's possible that we've parsed a block argument through our
// call to parse_arguments. If we found one, we should mark it
// as invalid and destroy it, as we don't have a place for it.
if (arguments.block != NULL) {
pm_parser_err_node(parser, arguments.block, PM_ERR_UNEXPECTED_BLOCK_ARGUMENT);
pm_node_unreference(parser, arguments.block);
arguments.block = NULL;
}
}

switch (keyword.type) {
Expand Down
33 changes: 33 additions & 0 deletions test/prism/errors/block_pass_return_value.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
return &b
^ unexpected '&', expecting end-of-input
^ unexpected '&', ignoring it

return(&b)
^ unexpected '&', ignoring it
^ unexpected '&', expecting end-of-input
^ unexpected '&', ignoring it
^ expected a matching `)`
^ unexpected '&', expecting end-of-input
^ unexpected '&', ignoring it
^ unexpected ')', expecting end-of-input
^ unexpected ')', ignoring it

return a, &b
^~ block argument should not be given

return(a, &b)
^~ unexpected write target
^ unexpected '&', expecting end-of-input
^ unexpected '&', ignoring it
^ expected a matching `)`
^ unexpected '&', expecting end-of-input
^ unexpected '&', ignoring it
^ unexpected ')', expecting end-of-input
^ unexpected ')', ignoring it

tap { break a, &b }
^~ block argument should not be given

tap { next a, &b }
^~ block argument should not be given