📘
[Bug #21097] rescue + in が1行で混ざっている場合に parse.y と prism で挙動が異なるというバグ報告
[Bug #21097] x = a rescue b in c
and def f = a rescue b in c
parsed differently between parse.y and prism
-
x = a rescue b in c
とdef f = a rescue b in c
がparse.y
とprism
で挙動が異なるというバグ報告 - 各コードは以下のように解釈されるらしい
x = a rescue b in c
(x = (a rescue b)) in c # parse.y, prism(ruby 3.4)
x = (a rescue (b in c)) # prism(ruby 3.5)
def f = a rescue b in c #=> true(parse.y), :f(prism)
(def f = (a rescue b)) in c # parse.y
def f = (a rescue (b in c)) # prism
- ややこしい…パッと見、何が違うのかわかりづらいんですが前者は式を評価したときの結果が Ruby 3.5-dev で異なります
a = 1
b = 2
c = 3
# parse.y は in の結果が返ってきて prism は代入式の結果が返ってくる
(x = (a rescue b)) in c
x = (a rescue (b in c))
pp (x = a rescue b in c)
# parse.y => true
# prism => 1
- 後者も同じような感じですね
- いつも忘れるんですが
式1 rescue 式2
は式1
を評価し、例外が発生すれば式2
を評価するような処理になります
Discussion