From ae347b74c9081c760053d57e71f619b59d1d5f75 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Fri, 15 May 2026 20:50:15 +0200 Subject: [PATCH 1/2] Reject `END { next }` as well https://github.com/ruby/ruby/commit/11de89ca1a94899535875ea594962c79713615b1 --- snapshots/3.3-4.0/end_block_exit.txt | 33 +++++++++++++------ snapshots/end_block_exit.txt | 20 ----------- src/prism.c | 3 -- test/prism/errors/4.1/end_block_exit.txt | 5 +++ .../prism/fixtures/3.3-4.0/end_block_exit.txt | 4 +++ test/prism/fixtures/end_block_exit.txt | 3 -- 6 files changed, 32 insertions(+), 36 deletions(-) delete mode 100644 snapshots/end_block_exit.txt delete mode 100644 test/prism/fixtures/end_block_exit.txt diff --git a/snapshots/3.3-4.0/end_block_exit.txt b/snapshots/3.3-4.0/end_block_exit.txt index 04e2c3b668..d3252ac6e8 100644 --- a/snapshots/3.3-4.0/end_block_exit.txt +++ b/snapshots/3.3-4.0/end_block_exit.txt @@ -1,10 +1,10 @@ -@ ProgramNode (location: (1,0)-(7,1)) +@ ProgramNode (location: (1,0)-(11,1)) ├── flags: ∅ ├── locals: [] └── statements: - @ StatementsNode (location: (1,0)-(7,1)) + @ StatementsNode (location: (1,0)-(11,1)) ├── flags: ∅ - └── body: (length: 2) + └── body: (length: 3) ├── @ PostExecutionNode (location: (1,0)-(3,1)) │ ├── flags: newline │ ├── statements: @@ -18,16 +18,29 @@ │ ├── keyword_loc: (1,0)-(1,3) = "END" │ ├── opening_loc: (1,4)-(1,5) = "{" │ └── closing_loc: (3,0)-(3,1) = "}" - └── @ PostExecutionNode (location: (5,0)-(7,1)) + ├── @ PostExecutionNode (location: (5,0)-(7,1)) + │ ├── flags: newline + │ ├── statements: + │ │ @ StatementsNode (location: (6,2)-(6,7)) + │ │ ├── flags: ∅ + │ │ └── body: (length: 1) + │ │ └── @ BreakNode (location: (6,2)-(6,7)) + │ │ ├── flags: newline + │ │ ├── arguments: ∅ + │ │ └── keyword_loc: (6,2)-(6,7) = "break" + │ ├── keyword_loc: (5,0)-(5,3) = "END" + │ ├── opening_loc: (5,4)-(5,5) = "{" + │ └── closing_loc: (7,0)-(7,1) = "}" + └── @ PostExecutionNode (location: (9,0)-(11,1)) ├── flags: newline ├── statements: - │ @ StatementsNode (location: (6,2)-(6,7)) + │ @ StatementsNode (location: (10,2)-(10,6)) │ ├── flags: ∅ │ └── body: (length: 1) - │ └── @ BreakNode (location: (6,2)-(6,7)) + │ └── @ NextNode (location: (10,2)-(10,6)) │ ├── flags: newline │ ├── arguments: ∅ - │ └── keyword_loc: (6,2)-(6,7) = "break" - ├── keyword_loc: (5,0)-(5,3) = "END" - ├── opening_loc: (5,4)-(5,5) = "{" - └── closing_loc: (7,0)-(7,1) = "}" + │ └── keyword_loc: (10,2)-(10,6) = "next" + ├── keyword_loc: (9,0)-(9,3) = "END" + ├── opening_loc: (9,4)-(9,5) = "{" + └── closing_loc: (11,0)-(11,1) = "}" diff --git a/snapshots/end_block_exit.txt b/snapshots/end_block_exit.txt deleted file mode 100644 index 4acc5f4218..0000000000 --- a/snapshots/end_block_exit.txt +++ /dev/null @@ -1,20 +0,0 @@ -@ ProgramNode (location: (1,0)-(3,1)) -├── flags: ∅ -├── locals: [] -└── statements: - @ StatementsNode (location: (1,0)-(3,1)) - ├── flags: ∅ - └── body: (length: 1) - └── @ PostExecutionNode (location: (1,0)-(3,1)) - ├── flags: newline - ├── statements: - │ @ StatementsNode (location: (2,2)-(2,6)) - │ ├── flags: ∅ - │ └── body: (length: 1) - │ └── @ NextNode (location: (2,2)-(2,6)) - │ ├── flags: newline - │ ├── arguments: ∅ - │ └── keyword_loc: (2,2)-(2,6) = "next" - ├── keyword_loc: (1,0)-(1,3) = "END" - ├── opening_loc: (1,4)-(1,5) = "{" - └── closing_loc: (3,0)-(3,1) = "}" diff --git a/src/prism.c b/src/prism.c index 3172799283..e2bdd56a59 100644 --- a/src/prism.c +++ b/src/prism.c @@ -15332,9 +15332,6 @@ parse_block_exit(pm_parser_t *parser, pm_node_t *node) { if (parser->version < PM_OPTIONS_VERSION_CRUBY_4_1) { return; } - if (PM_NODE_TYPE_P(node, PM_NEXT_NODE)) { - return; - } } PRISM_FALLTHROUGH case PM_CONTEXT_DEF: diff --git a/test/prism/errors/4.1/end_block_exit.txt b/test/prism/errors/4.1/end_block_exit.txt index f8fc59d1a3..a4a1e9bc2c 100644 --- a/test/prism/errors/4.1/end_block_exit.txt +++ b/test/prism/errors/4.1/end_block_exit.txt @@ -3,3 +3,8 @@ END { ^~~~~ Invalid break } +END { + next + ^~~~ Invalid next +} + diff --git a/test/prism/fixtures/3.3-4.0/end_block_exit.txt b/test/prism/fixtures/3.3-4.0/end_block_exit.txt index 53afa1e2f4..8ebf0d6369 100644 --- a/test/prism/fixtures/3.3-4.0/end_block_exit.txt +++ b/test/prism/fixtures/3.3-4.0/end_block_exit.txt @@ -5,3 +5,7 @@ END { END { break } + +END { + next +} diff --git a/test/prism/fixtures/end_block_exit.txt b/test/prism/fixtures/end_block_exit.txt deleted file mode 100644 index 1f64dcb6ed..0000000000 --- a/test/prism/fixtures/end_block_exit.txt +++ /dev/null @@ -1,3 +0,0 @@ -END { - next -} From ce0179e18ae2a1af7457ba0074994d7be692ec3c Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Fri, 15 May 2026 20:54:39 +0200 Subject: [PATCH 2/2] Rename `putstring` instruction as `dupstring` https://github.com/ruby/ruby/commit/072a6a4a10e94410e2f3d70ea0952ec8ad7f63d8 --- src/prism.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prism.c b/src/prism.c index e2bdd56a59..c046aefce6 100644 --- a/src/prism.c +++ b/src/prism.c @@ -5074,7 +5074,7 @@ pm_interpolated_regular_expression_node_closing_set(pm_parser_t *parser, pm_inte * PM_NODE_FLAG_STATIC_LITERAL indicates that the node should be treated as a * single static literal string that can be pushed onto the stack on its own. * Note that this doesn't necessarily mean that the string will be frozen or - * not; the instructions in CRuby will be either putobject or putstring, + * not; the instructions in CRuby will be either either putobject, dupstring or dupchilledstring, * depending on the combination of `--enable-frozen-string-literal`, * `# frozen_string_literal: true`, and whether or not there is interpolation. *