check and show a warning for incorrect yield.
* compile.c (check_yield_place): this function check the yield location. * show a warning if yield in `class` syntax. [Feature #15575] * do strict check for toplevel `yield`. Without this patch, `1.times{ yield }` in toplevel is valid-syntax (raise LocalJumpError at runtime) although toplevel simple `yield` is not valid syntax. This patch make them syntax error. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8bda94f78c
commit
0fc597f29c
23
compile.c
23
compile.c
@ -5921,6 +5921,21 @@ qcall_branch_end(rb_iseq_t *iseq, LINK_ANCHOR *const ret, LABEL *else_label, VAL
|
||||
ADD_LABEL(ret, end_label);
|
||||
}
|
||||
|
||||
static int
|
||||
check_yield_place(const rb_iseq_t *iseq)
|
||||
{
|
||||
switch (iseq->body->local_iseq->body->type) {
|
||||
case ISEQ_TYPE_TOP:
|
||||
case ISEQ_TYPE_MAIN:
|
||||
return FALSE;
|
||||
case ISEQ_TYPE_CLASS:
|
||||
rb_warn("`yield' in class syntax will not be supported from Ruby 3.0. [Feature #15575]");
|
||||
return TRUE;
|
||||
default:
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, int popped)
|
||||
{
|
||||
@ -6827,11 +6842,11 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
|
||||
struct rb_call_info_kw_arg *keywords = NULL;
|
||||
|
||||
INIT_ANCHOR(args);
|
||||
if (body->type == ISEQ_TYPE_TOP ||
|
||||
body->type == ISEQ_TYPE_MAIN) {
|
||||
|
||||
if (check_yield_place(iseq) == FALSE) {
|
||||
COMPILE_ERROR(ERROR_ARGS "Invalid yield");
|
||||
goto ng;
|
||||
}
|
||||
goto ng;
|
||||
}
|
||||
|
||||
if (node->nd_head) {
|
||||
argc = setup_args(iseq, args, node->nd_head, &flag, &keywords);
|
||||
|
Loading…
x
Reference in New Issue
Block a user