diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-09-13 21:55:12 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-09-15 01:09:06 +0900 |
| commit | e8896a31d48e5797df3878696dcb50aed85b87c2 (patch) | |
| tree | 4c8d7ed5ee5b8f6b517fe3dafb7fdcdd0dac3a73 /parse.y | |
| parent | 3f492921c8b7c787b150445e4f28691d9a886dcc (diff) | |
[Bug #19877] Literals cannot have singleton methods even in blocks
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8440
Diffstat (limited to 'parse.y')
| -rw-r--r-- | parse.y | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -917,6 +917,15 @@ set_embraced_location(NODE *node, const rb_code_location_t *beg, const rb_code_l nd_set_line(node, beg->end_pos.lineno); } +static NODE * +last_expr_node(NODE *expr) +{ + if (nd_type_p(expr, NODE_BLOCK)) { + expr = expr->nd_end->nd_head; + } + return expr; +} + #define yyparse ruby_yyparse static NODE* cond(struct parser_params *p, NODE *node, const YYLTYPE *loc); @@ -6050,16 +6059,18 @@ singleton : var_ref | '(' {SET_LEX_STATE(EXPR_BEG);} expr rparen { /*%%%*/ - switch (nd_type($3)) { + NODE *expr = last_expr_node($3); + switch (nd_type(expr)) { case NODE_STR: case NODE_DSTR: case NODE_XSTR: case NODE_DXSTR: case NODE_DREGX: case NODE_LIT: + case NODE_DSYM: case NODE_LIST: case NODE_ZLIST: - yyerror1(&@3, "can't define singleton method for literals"); + yyerror1(&expr->nd_loc, "can't define singleton method for literals"); break; default: value_expr($3); |
