Regression: IntegerNode values are incorrect after syntax errors

クローズ
#4,319 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #4332 @kddnewton による — マージ済み

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
57/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
c, ruby
領域
backend, compilers

調査の方向性

Start by reproducing the incorrect IntegerNode values with Prism 2.1.0 using the examples Prism.parse("1 2 3") and Prism.parse("1i 2i 3i"), then compare the relevant parser behavior with Prism 1.9.0. The issue does not name source files or tests, so trace integer literal parsing and its regression coverage from the parser entry point. Done means each IntegerNode retains the value at its own source location, including when syntax errors are present.

索引モデルが issue の本文から書いたものです。

説明

Affected version: Prism 2.1.0
Known working version: Prism 1.9.0

In Prism 2.1.0, parsing consecutive integer literals separated by whitespace produces an AST with incorrect values for some IntegerNode instances.

Reproduction
Prism.parse("1 2 3")
Prism.parse("1i 2i 3i")

In Prism 2.1.0, the resulting AST contains:

      @ StatementsNode (location: (1,0)-(1,5))
      ├── flags: ∅
      └── body: (length: 3)
          ├── @ IntegerNode (location: (1,0)-(1,1))
          │   ├── flags: newline, static_literal, decimal
          │   └── value: 2
          ├── @ IntegerNode (location: (1,2)-(1,3))
          │   ├── flags: newline, static_literal, decimal
          │   └── value: 2
          └── @ IntegerNode (location: (1,4)-(1,5))
              ├── flags: newline, static_literal, decimal
              └── value: 3,
      @ StatementsNode (location: (1,0)-(1,8))
      ├── flags: ∅
      └── body: (length: 3)
          ├── @ ImaginaryNode (location: (1,0)-(1,2))
          │   ├── flags: newline, static_literal
          │   └── numeric:
          │       @ IntegerNode (location: (1,0)-(1,1))
          │       ├── flags: static_literal, decimal
          │       └── value: 2
          ├── @ ImaginaryNode (location: (1,3)-(1,5))
          │   ├── flags: newline, static_literal
          │   └── numeric:
          │       @ IntegerNode (location: (1,3)-(1,4))
          │       ├── flags: static_literal, decimal
          │       └── value: 3
          └── @ ImaginaryNode (location: (1,6)-(1,8))
              ├── flags: newline, static_literal
              └── numeric:
                  @ IntegerNode (location: (1,6)-(1,7))
                  ├── flags: static_literal, decimal
                  └── value: 3,

The first node represents the literal 1, but its value is 2.

FloatNode and RationalNode nodes generate correct values ​​in a similar case.

Comparison with Prism 1.9.0

This behavior does not occur in Prism 1.9.0.

      @ StatementsNode (location: (1,0)-(1,5))
      ├── flags: ∅
      └── body: (length: 3)
          ├── @ IntegerNode (location: (1,0)-(1,1))
          │   ├── flags: newline, static_literal, decimal
          │   └── value: 1
          ├── @ IntegerNode (location: (1,2)-(1,3))
          │   ├── flags: newline, static_literal, decimal
          │   └── value: 2
          └── @ IntegerNode (location: (1,4)-(1,5))
              ├── flags: newline, static_literal, decimal
              └── value: 3,
      @ StatementsNode (location: (1,0)-(1,8))
      ├── flags: ∅
      └── body: (length: 3)
          ├── @ ImaginaryNode (location: (1,0)-(1,2))
          │   ├── flags: newline, static_literal
          │   └── numeric:
          │       @ IntegerNode (location: (1,0)-(1,1))
          │       ├── flags: static_literal, decimal
          │       └── value: 1
          ├── @ ImaginaryNode (location: (1,3)-(1,5))
          │   ├── flags: newline, static_literal
          │   └── numeric:
          │       @ IntegerNode (location: (1,3)-(1,4))
          │       ├── flags: static_literal, decimal
          │       └── value: 2
          └── @ ImaginaryNode (location: (1,6)-(1,8))
              ├── flags: newline, static_literal
              └── numeric:
                  @ IntegerNode (location: (1,6)-(1,7))
                  ├── flags: static_literal, decimal
                  └── value: 3,
Expected behavior

Each IntegerNode should retain the value corresponding to its own source location, even when the input contains syntax errors.
Since Prism 1.9.0 handled these cases correctly, this appears to be a regression introduced in a later version.

主要言語
C
スター
1k
フォーク
202
平均マージ
7時間 52分
マージ済み PR(30日)
76

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。