🐈

[Bug #21985] RubyVM::AST.parse('-1') の location が正しくないというバグ報告

に公開

[Bug #21985] RubyVM::AST negative numbers do not include - in location

  • ``RubyVM::AbstractSyntaxTree.parse("-1")location` が正しくないというバグ報告
  • ちょっとわかりづらいんですが #first_column0 を期待しているんですが 1 が返ってきてしまっているという内容
# こっちは問題なく 0 からはじまる
location = RubyVM::AbstractSyntaxTree.parse("1").children.last.locations.first
pp location.then { [_1.first_column, _1.first_lineno, _1.last_column, _1.last_lineno] }
# => [0, 1, 1, 1]

# -1 の場合は 1 からはじまっている
location = RubyVM::AbstractSyntaxTree.parse("-1").children.last.locations.first
pp location.then { [_1.first_column, _1.first_lineno, _1.last_column, _1.last_lineno] }
# => [1, 1, 2, 1]
  • この不具合は開発版の Ruby 4.1-dev で修正済み
location = RubyVM::AbstractSyntaxTree.parse("-1").children.last.locations.first
pp location.then { [_1.first_column, _1.first_lineno, _1.last_column, _1.last_lineno] }
# Ruby 4.0 => [1, 1, 2, 1]
# Ruby 4.1 => [0, 1, 2, 1]
GitHubで編集を提案

Discussion