mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Don't emit warning when the pattern of one-line pattern matching is just a variable pattern
https://github.com/ruby/dev-meeting-log/blob/master/DevelopersMeeting20201210Japan.md#feature-17371-reintroduce-expr-in-pat-ktsj
This commit is contained in:
parent
1b45174aea
commit
a8cf526ae9
4 changed files with 19 additions and 10 deletions
17
parse.y
17
parse.y
|
@ -502,6 +502,7 @@ static NODE *new_find_pattern(struct parser_params *p, NODE *constant, NODE *fnd
|
||||||
static NODE *new_find_pattern_tail(struct parser_params *p, ID pre_rest_arg, NODE *args, ID post_rest_arg, const YYLTYPE *loc);
|
static NODE *new_find_pattern_tail(struct parser_params *p, ID pre_rest_arg, NODE *args, ID post_rest_arg, const YYLTYPE *loc);
|
||||||
static NODE *new_hash_pattern(struct parser_params *p, NODE *constant, NODE *hshptn, const YYLTYPE *loc);
|
static NODE *new_hash_pattern(struct parser_params *p, NODE *constant, NODE *hshptn, const YYLTYPE *loc);
|
||||||
static NODE *new_hash_pattern_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, const YYLTYPE *loc);
|
static NODE *new_hash_pattern_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, const YYLTYPE *loc);
|
||||||
|
static void warn_one_line_pattern_matching(struct parser_params *p, NODE *node, NODE *pattern);
|
||||||
|
|
||||||
static NODE *new_kw_arg(struct parser_params *p, NODE *k, const YYLTYPE *loc);
|
static NODE *new_kw_arg(struct parser_params *p, NODE *k, const YYLTYPE *loc);
|
||||||
static NODE *args_with_numbered(struct parser_params*,NODE*,int);
|
static NODE *args_with_numbered(struct parser_params*,NODE*,int);
|
||||||
|
@ -1661,10 +1662,7 @@ expr : command_call
|
||||||
p->ctxt.in_kwarg = $<ctxt>3.in_kwarg;
|
p->ctxt.in_kwarg = $<ctxt>3.in_kwarg;
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$ = NEW_CASE3($1, NEW_IN($5, 0, 0, &@5), &@$);
|
$$ = NEW_CASE3($1, NEW_IN($5, 0, 0, &@5), &@$);
|
||||||
|
warn_one_line_pattern_matching(p, $$, $5);
|
||||||
if (rb_warning_category_enabled_p(RB_WARN_CATEGORY_EXPERIMENTAL))
|
|
||||||
rb_warn0L(nd_line($$), "One-line pattern matching is experimental, and the behavior may change in future versions of Ruby!");
|
|
||||||
|
|
||||||
/*% %*/
|
/*% %*/
|
||||||
/*% ripper: case!($1, in!($5, Qnil, Qnil)) %*/
|
/*% ripper: case!($1, in!($5, Qnil, Qnil)) %*/
|
||||||
}
|
}
|
||||||
|
@ -11690,6 +11688,17 @@ new_hash_pattern_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, co
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
warn_one_line_pattern_matching(struct parser_params *p, NODE *node, NODE *pattern)
|
||||||
|
{
|
||||||
|
enum node_type type;
|
||||||
|
type = nd_type(pattern);
|
||||||
|
|
||||||
|
if (rb_warning_category_enabled_p(RB_WARN_CATEGORY_EXPERIMENTAL) &&
|
||||||
|
!(type == NODE_LASGN || type == NODE_DASGN || type == NODE_DASGN_CURR))
|
||||||
|
rb_warn0L(nd_line(node), "One-line pattern matching is experimental, and the behavior may change in future versions of Ruby!");
|
||||||
|
}
|
||||||
|
|
||||||
static NODE*
|
static NODE*
|
||||||
dsym_node(struct parser_params *p, NODE *node, const YYLTYPE *loc)
|
dsym_node(struct parser_params *p, NODE *node, const YYLTYPE *loc)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,11 +33,11 @@ ruby_version_is "2.7" do
|
||||||
describe "The -W command line option with :no-experimental" do
|
describe "The -W command line option with :no-experimental" do
|
||||||
before do
|
before do
|
||||||
ruby_version_is ""..."3.0" do
|
ruby_version_is ""..."3.0" do
|
||||||
@src = 'case 0; in a; end'
|
@src = 'case [0, 1]; in [a, b]; end'
|
||||||
end
|
end
|
||||||
|
|
||||||
ruby_version_is "3.0" do
|
ruby_version_is "3.0" do
|
||||||
@src = '1 => a'
|
@src = '[0, 1] => [a, b]'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,11 @@ ruby_version_is '2.7' do
|
||||||
describe ":experimental" do
|
describe ":experimental" do
|
||||||
before do
|
before do
|
||||||
ruby_version_is ""..."3.0" do
|
ruby_version_is ""..."3.0" do
|
||||||
@src = 'case 0; in a; end'
|
@src = 'case [0, 1]; in [a, b]; end'
|
||||||
end
|
end
|
||||||
|
|
||||||
ruby_version_is "3.0" do
|
ruby_version_is "3.0" do
|
||||||
@src = '1 => a'
|
@src = '[0, 1] => [a, b]'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -43,11 +43,11 @@ ruby_version_is "2.7" do
|
||||||
describe "warning" do
|
describe "warning" do
|
||||||
before do
|
before do
|
||||||
ruby_version_is ""..."3.0" do
|
ruby_version_is ""..."3.0" do
|
||||||
@src = 'case 0; in a; end'
|
@src = 'case [0, 1]; in [a, b]; end'
|
||||||
end
|
end
|
||||||
|
|
||||||
ruby_version_is "3.0" do
|
ruby_version_is "3.0" do
|
||||||
@src = '1 => a'
|
@src = '[0, 1] => [a, b]'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue