"expr_value" can be error

So that "IF" node is kept in the case below

```
def m
  if
end
```

[Feature #19013]
This commit is contained in:
yui-knk 2022-10-01 17:53:39 +09:00 committed by Yuichiro Kaneko
parent 4bfdf6d06d
commit 3531086095
Notes: git 2022-10-08 17:59:34 +09:00
2 changed files with 41 additions and 0 deletions

View File

@ -1901,6 +1901,12 @@ expr_value : expr
value_expr($1);
$$ = $1;
}
| error
{
/*%%%*/
$$ = NEW_ERROR(&@$);
/*% %*/
}
;
expr_value_do : {COND_PUSH(1);} expr_value do {COND_POP();}

View File

@ -1007,4 +1007,39 @@ dummy
body: nil))))))
EXP
end
def test_error_tolerant_expr_value_can_be_error
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
def m
if
end
STR
str = ""
PP.pp(node, str)
assert_equal(<<~EXP, str)
(SCOPE@1:0-3:3
tbl: []
args: nil
body:
(DEFN@1:0-3:3
mid: :m
body:
(SCOPE@1:0-3:3
tbl: []
args:
(ARGS@1:5-1:5
pre_num: 0
pre_init: nil
opt: nil
first_post: nil
post_num: 0
post_init: nil
rest: nil
kw: nil
kwrest: nil
block: nil)
body: (IF@2:2-3:3 (ERROR@3:0-3:3) nil nil))))
EXP
end
end