codegen.c: yield outside of method is now SyntaxError.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-03-31 15:57:43 +09:00
parent a7ca5a9b6e
commit 9f85c5e483
2 changed files with 6 additions and 5 deletions
+2 -2
View File
@@ -2355,7 +2355,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_YIELD:
{
codegen_scope *s2 = s;
int lv = 0, ainfo = 0;
int lv = 0, ainfo = -1;
int n = 0, sendv = 0;
while (!s2->mscope) {
@@ -2365,8 +2365,8 @@ codegen(codegen_scope *s, node *tree, int val)
}
if (s2) {
ainfo = s2->ainfo;
if (ainfo < 0) codegen_error(s, "invalid yield (SyntaxError)");
}
if (ainfo < 0) codegen_error(s, "invalid yield (SyntaxError)");
push();
if (tree) {
n = gen_values(s, tree, VAL, 0);
+4 -3
View File
@@ -35,9 +35,10 @@ assert('super', '11.3.4') do
end
assert('yield', '11.3.5') do
assert_raise LocalJumpError do
yield
end
# it's syntax error now
# assert_raise LocalJumpError do
# yield
# end
assert_raise LocalJumpError do
o = Object.new
def o.foo