Skip to content

Commit b24cd45

Browse files
committed
Reject END { break } for Ruby 3.5
For [Bug #20409]
1 parent a6f7e60 commit b24cd45

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@ ProgramNode (location: (1,0)-(3,1))
2+
├── flags: ∅
3+
├── locals: []
4+
└── statements:
5+
@ StatementsNode (location: (1,0)-(3,1))
6+
├── flags: ∅
7+
└── body: (length: 1)
8+
└── @ PostExecutionNode (location: (1,0)-(3,1))
9+
├── flags: newline
10+
├── statements:
11+
│ @ StatementsNode (location: (2,2)-(2,7))
12+
│ ├── flags: ∅
13+
│ └── body: (length: 1)
14+
│ └── @ BreakNode (location: (2,2)-(2,7))
15+
│ ├── flags: newline
16+
│ ├── arguments: ∅
17+
│ └── keyword_loc: (2,2)-(2,7) = "break"
18+
├── keyword_loc: (1,0)-(1,3) = "END"
19+
├── opening_loc: (1,4)-(1,5) = "{"
20+
└── closing_loc: (3,0)-(3,1) = "}"

src/prism.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15799,7 +15799,6 @@ parse_block_exit(pm_parser_t *parser, pm_node_t *node) {
1579915799
case PM_CONTEXT_LAMBDA_ENSURE:
1580015800
case PM_CONTEXT_LAMBDA_RESCUE:
1580115801
case PM_CONTEXT_LOOP_PREDICATE:
15802-
case PM_CONTEXT_POSTEXE:
1580315802
case PM_CONTEXT_UNTIL:
1580415803
case PM_CONTEXT_WHILE:
1580515804
// These are the good cases. We're allowed to have a block exit
@@ -15812,10 +15811,16 @@ parse_block_exit(pm_parser_t *parser, pm_node_t *node) {
1581215811
case PM_CONTEXT_DEF_RESCUE:
1581315812
case PM_CONTEXT_MAIN:
1581415813
case PM_CONTEXT_PREEXE:
15814+
case PM_CONTEXT_POSTEXE:
1581515815
case PM_CONTEXT_SCLASS:
1581615816
case PM_CONTEXT_SCLASS_ELSE:
1581715817
case PM_CONTEXT_SCLASS_ENSURE:
1581815818
case PM_CONTEXT_SCLASS_RESCUE:
15819+
// https://bugs.ruby-lang.org/issues/20409
15820+
if (context_node->context == PM_CONTEXT_POSTEXE && parser->version < PM_OPTIONS_VERSION_CRUBY_3_5) {
15821+
return;
15822+
}
15823+
1581915824
// These are the bad cases. We're not allowed to have a block
1582015825
// exit in these contexts.
1582115826
//
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
END {
2+
break
3+
^~~~~ Invalid break
4+
}
5+

test/prism/errors_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class ErrorsTest < TestCase
99
base = File.expand_path("errors", __dir__)
1010
filepaths = Dir["**/*.txt", base: base]
1111

12+
PARSE_Y_EXCLUDES = [
13+
]
14+
1215
filepaths.each do |filepath|
1316
ruby_versions_for(filepath).each do |version|
1417
define_method(:"test_#{version}_#{File.basename(filepath, ".txt")}") do
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
END {
2+
break
3+
}

0 commit comments

Comments
 (0)