VB -> C#: Local variables should be pulled before labels

オープン
#910 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
csharp
領域
tooling

調査の方向性

ローカル変数の宣言とラベルを処理する VB.NET から C# への変換パスから始め、提示された入力および期待される出力と比較してください。例の回帰テストを追加し、生成されたローカル宣言がラベルより前に配置されることを確認してください。これにより、変換後のプログラムが無限ループに陥らなくなります。

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

説明

Good for coding agent output logic error VB -> C#
VB.Net input code
Public Shared Sub Main()
    Label:
    Dim number As Integer
    number += 1
    If number = 1 Then GoTo Label
        
    Console.WriteLine(number) ' will print 2
End Sub
Erroneous output
public static void Main()
{
Label:
    ; // that's ugly but still compiles
    var number = default(int);
    number += 1;
    if (number == 1)
        goto Label;

    Console.WriteLine(number);  // will never be called, infinite loop
}
Expected output
public static void Main()
{
    var number = default(int);
Label:
    number += 1;
    if (number == 1)
        goto Label;

    Console.WriteLine(number); 
}
Details

Very rare but unfortunately possible to happen in large, legacy code bases.
Maybe every variable initialization should be moved to the beginning of the procedure/before all labels when there are goto statements?
Related to #897

Even if the scope of a variable is limited to a block, its lifetime is still that of the entire procedure. If you enter the block more than once during the procedure, each block variable retains its previous value. To avoid unexpected results in such a case, it is wise to initialize block variables at the beginning of the block.

主要言語
C#
スター
918
フォーク
244
平均マージ
1日 10時間
マージ済み PR(30日)
29

環境構築

はじめの一歩

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

icsharpcode/CodeConverter のほかの issue

icsharpcode/CodeConverter の issue をすべて見る

似ている issue

C# の issue をもっと見る

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

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