diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-10-02 22:06:32 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-10-02 23:20:03 +0900 |
| commit | 9059dfce12995451a4374330baab49177fa717be (patch) | |
| tree | 2c31bbba49d44a5ffe6914044c6a5be2f021b722 /test | |
| parent | 63e504d6e65765740a592ee785147e5eff0d9aed (diff) | |
`yield` cannot be placed outside methods even in blocks
Diffstat (limited to 'test')
| -rw-r--r-- | test/prism/parse_test.rb | 8 | ||||
| -rw-r--r-- | test/ruby/test_ast.rb | 2 |
2 files changed, 9 insertions, 1 deletions
diff --git a/test/prism/parse_test.rb b/test/prism/parse_test.rb index 3c0d584a12..aed41b5f84 100644 --- a/test/prism/parse_test.rb +++ b/test/prism/parse_test.rb @@ -89,11 +89,17 @@ module Prism src = source case relative - when /break|next|redo|if|unless|rescue|control|keywords|retry|yield|\/args_assocs/ + when /break|next|redo|if|unless|rescue|control|keywords|retry/ # Uncaught syntax errors: Invalid break, Invalid next src = "->do\nrescue\n#{src}\nend" ripper_should_match = false end + case src + when /^ *yield/ + # Uncaught syntax errors: Invalid yield + src = "def __invalid_yield__\n#{src}\nend" + ripper_should_match = false + end # Make sure that it can be correctly parsed by Ripper. If it can't, then we have a fixture # that is invalid Ruby. diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index f2c746aafa..c8617d50f0 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -312,11 +312,13 @@ class TestAst < Test::Unit::TestCase assert_invalid_parse(msg, "class C; yield; end") assert_invalid_parse(msg, "BEGIN {yield}") assert_invalid_parse(msg, "END {yield}") + assert_invalid_parse(msg, "-> {yield}") assert_invalid_parse(msg, "yield true") assert_invalid_parse(msg, "class C; yield true; end") assert_invalid_parse(msg, "BEGIN {yield true}") assert_invalid_parse(msg, "END {yield true}") + assert_invalid_parse(msg, "-> {yield true}") assert_parse("!defined?(yield)") assert_parse("class C; defined?(yield); end") |
