ruby-changes:58960
From: Nobuyoshi <ko1@a...>
Date: Sat, 30 Nov 2019 00:21:49 +0900 (JST)
Subject: [ruby-changes:58960] d1ef4fd08e (master): Make single line pattern matching void expression
https://git.ruby-lang.org/ruby.git/commit/?id=d1ef4fd08e From d1ef4fd08e60adcbcb4feeb55f767ff3d80b65a0 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sat, 30 Nov 2019 00:15:29 +0900 Subject: Make single line pattern matching void expression Instead of returning `nil`, raise a syntax error if its value is used. [Feature #16355] diff --git a/parse.y b/parse.y index c1df306..15c9b41 100644 --- a/parse.y +++ b/parse.y @@ -10740,6 +10740,17 @@ value_expr_check(struct parser_params *p, NODE *node) https://github.com/ruby/ruby/blob/trunk/parse.y#L10740 case NODE_RETRY: return void_node ? void_node : node; + case NODE_CASE3: + if (!node->nd_body || nd_type(node->nd_body) != NODE_IN) { + compile_error(p, "unexpected node"); + return NULL; + } + if (node->nd_body->nd_body) { + return NULL; + } + /* single line pattern matching */ + return void_node ? void_node : node; + case NODE_BLOCK: while (node->nd_next) { node = node->nd_next; diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb index 50bab51..5308ec3 100644 --- a/test/ruby/test_pattern_matching.rb +++ b/test/ruby/test_pattern_matching.rb @@ -1261,12 +1261,12 @@ END https://github.com/ruby/ruby/blob/trunk/test/ruby/test_pattern_matching.rb#L1261 ################################################################ def test_modifier_in - assert_nil (1 in a) + 1 in a assert_equal 1, a assert_raise(NoMatchingPatternError) do {a: 1} in {a: 0} end - assert_valid_syntax "p(({} in {a:}), a:\n 1)" + assert_syntax_error("if {} in {a:}; end", /void value expression/) assert_syntax_error(%q{ 1 in a, b }, /unexpected/, '[ruby-core:95098]') -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/