summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2024-07-24 11:15:25 +0900
committerNobuyoshi Nakada <[email protected]>2024-07-24 14:44:32 +0900
commite642ddf7ae86e306674559ae745823fdbf56ea10 (patch)
tree2f60c4b4d5509e784e9fbd6cd4dcd69ca78dbb02 /test
parentf2f9d6ce49aaee6b6414c8442082166cf733ab00 (diff)
[Bug #20647] Disallow `return` directly within a singleton class
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11234
Diffstat (limited to 'test')
-rw-r--r--test/prism/errors/dont_allow_return_inside_sclass_body.txt3
-rw-r--r--test/ruby/test_class.rb1
2 files changed, 4 insertions, 0 deletions
diff --git a/test/prism/errors/dont_allow_return_inside_sclass_body.txt b/test/prism/errors/dont_allow_return_inside_sclass_body.txt
new file mode 100644
index 0000000000..c29fe01728
--- /dev/null
+++ b/test/prism/errors/dont_allow_return_inside_sclass_body.txt
@@ -0,0 +1,3 @@
+class << A; return; end
+ ^~~~~~ Invalid return in class/module body
+
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb
index 710b8a6f7b..38a6e9eb9f 100644
--- a/test/ruby/test_class.rb
+++ b/test/ruby/test_class.rb
@@ -316,6 +316,7 @@ class TestClass < Test::Unit::TestCase
def test_invalid_return_from_class_definition
assert_syntax_error("class C; return; end", /Invalid return/)
+ assert_syntax_error("class << Object; return; end", /Invalid return/)
end
def test_invalid_yield_from_class_definition