[前][次][番号順一覧][スレッド一覧]

ruby-changes:72359

From: Nobuyoshi <ko1@a...>
Date: Wed, 29 Jun 2022 14:13:27 +0900 (JST)
Subject: [ruby-changes:72359] 685efac059 (master): [Bug #18884] `class` cannot be just followed by modifiers

https://git.ruby-lang.org/ruby.git/commit/?id=685efac059

From 685efac05983dee44ce2d96c24f2fcb96a0aebe2 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Wed, 29 Jun 2022 14:13:15 +0900
Subject: [Bug #18884] `class` cannot be just followed by modifiers

---
 parse.y                 | 2 +-
 test/ruby/test_parse.rb | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/parse.y b/parse.y
index 4bda597834..f746a0c272 100644
--- a/parse.y
+++ b/parse.y
@@ -9235,7 +9235,7 @@ parse_ident(struct parser_params *p, int c, int cmd_state) https://github.com/ruby/ruby/blob/trunk/parse.y#L9235
 		    return keyword_do_block;
 		return keyword_do;
 	    }
-	    if (IS_lex_state_for(state, (EXPR_BEG | EXPR_LABELED)))
+	    if (IS_lex_state_for(state, (EXPR_BEG | EXPR_LABELED | EXPR_CLASS)))
 		return kw->id[0];
 	    else {
 		if (kw->id[0] != kw->id[1])
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 2841e20f6d..1d756441f8 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -1359,6 +1359,13 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L1359
     end;
   end
 
+  def test_if_after_class
+    assert_valid_syntax('module if true; Object end::Kernel; end')
+    assert_valid_syntax('module while true; break Object end::Kernel; end')
+    assert_valid_syntax('class if true; Object end::Kernel; end')
+    assert_valid_syntax('class while true; break Object end::Kernel; end')
+  end
+
 =begin
   def test_past_scope_variable
     assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]