Skip to content

Commit 7ea07dd

Browse files
Earlopainkddnewton
authored andcommitted
[Bug #21994] Drop warning for ambiguous regexp use
https://bugs.ruby-lang.org/issues/21994
1 parent d8a2f6c commit 7ea07dd

4 files changed

Lines changed: 10 additions & 12 deletions

File tree

parse.y

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9174,12 +9174,7 @@ static int
91749174
arg_ambiguous(struct parser_params *p, char c)
91759175
{
91769176
#ifndef RIPPER
9177-
if (c == '/') {
9178-
rb_warning1("ambiguity between regexp and two divisions: wrap regexp in parentheses or add a space after '%c' operator", WARN_I(c));
9179-
}
9180-
else {
9181-
rb_warning1("ambiguous first argument; put parentheses or a space even after '%c' operator", WARN_I(c));
9182-
}
9177+
rb_warning1("ambiguous first argument; put parentheses or a space even after '%c' operator", WARN_I(c));
91839178
#else
91849179
dispatch1(arg_ambiguous, rb_usascii_str_new(&c, 1));
91859180
#endif
@@ -11019,7 +11014,6 @@ parser_yylex(struct parser_params *p)
1101911014
}
1102011015
pushback(p, c);
1102111016
if (IS_SPCARG(c)) {
11022-
arg_ambiguous(p, '/');
1102311017
p->lex.strterm = NEW_STRTERM(str_regexp, '/', 0);
1102411018
return tREGEXP_BEG;
1102511019
}

prism/prism.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11043,7 +11043,10 @@ parser_lex(pm_parser_t *parser) {
1104311043
}
1104411044

1104511045
if (lex_state_spcarg_p(parser, space_seen)) {
11046-
pm_parser_warn_token(parser, &parser->current, PM_WARN_AMBIGUOUS_SLASH);
11046+
// https://bugs.ruby-lang.org/issues/21994
11047+
if (parser->version <= PM_OPTIONS_VERSION_CRUBY_4_0) {
11048+
pm_parser_warn_token(parser, &parser->current, PM_WARN_AMBIGUOUS_SLASH);
11049+
}
1104711050
lex_mode_push_regexp(parser, '\0', '/');
1104811051
LEX(PM_TOKEN_REGEXP_BEGIN);
1104911052
}

test/prism/result/warnings_test.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def test_ambiguous_ustar
1919
end
2020

2121
def test_ambiguous_regexp
22-
assert_warning("a /b/", "wrap regexp in parentheses")
22+
assert_warning("a /b/", "wrap regexp in parentheses", compare: false, version: "4.0")
23+
refute_warning("a /b/", compare: false, version: "4.1")
2324
end
2425

2526
def test_ambiguous_ampersand
@@ -408,8 +409,8 @@ def test_warnings_verbosity
408409
assert_equal "END in method; use at_exit", warning.message
409410
assert_equal :default, warning.level
410411

411-
warning = Prism.parse("foo /regexp/").warnings.first
412-
assert_equal "ambiguous `/`; wrap regexp in parentheses or add a space after `/` operator", warning.message
412+
warning = Prism.parse("foo +1").warnings.first
413+
assert_equal "ambiguous first argument; put parentheses or a space even after `+` operator", warning.message
413414
assert_equal :verbose, warning.level
414415
end
415416

test/ripper/test_parser_events.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def test_aref_field
233233

234234
def test_arg_ambiguous
235235
thru_arg_ambiguous = false
236-
parse('m //', :on_arg_ambiguous) {thru_arg_ambiguous = true}
236+
parse('m +1', :on_arg_ambiguous) {thru_arg_ambiguous = true}
237237
assert_equal true, thru_arg_ambiguous
238238
end
239239

0 commit comments

Comments
 (0)