Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

C# -> VB: most pattern matching fails to convert

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp, visualbasic
領域
tooling

調査の方向性

VisitIsPatternExpression と CommonConversions.ConvertToVariableDeclaratorOrNull の hoisting パスから始め、その後、リンクされたブランチの 6 つの特性テストを確認します。型、否定、関係、および定数パターンが、エラーや無効な Is 比較なしで、示されている VB の同等表現に変換され、完全なテストスイートが引き続きグリーンであれば完了です。

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

説明

C# -> VB
Input code
class Picture
{
}

class TestClass
{
    bool NegatedType(object o) => o is not string;

    bool NegatedNamedType(object o) => o is not Picture;

    int NegatedDeclaration(object o)
    {
        if (o is not string s) return -1;
        return s.Length;
    }

    bool Relational(int i) => i is > 0;

    bool ValueConstant(int i) => i is 5;
}
Erroneous output
Friend Class Picture
End Class

Friend Class TestClass
    Private Function NegatedType(o As Object) As Boolean
        ''' Cannot convert IsPatternExpressionSyntax, System.ArgumentOutOfRangeException: ... (Parameter 'node')
        ''' Actual value was not string.
    End Function

    Private Function NegatedNamedType(o As Object) As Boolean
        ''' Cannot convert IsPatternExpressionSyntax, System.ArgumentOutOfRangeException: ... (Parameter 'node')
        ''' Actual value was not Picture.
    End Function

    ''' Cannot convert MethodDeclarationSyntax, System.ArgumentOutOfRangeException: ... (Parameter 'node')
    ''' Actual value was not string s.

    Private Function Relational(i As Integer) As Boolean
        ''' Cannot convert IsPatternExpressionSyntax, System.ArgumentOutOfRangeException: ... (Parameter 'node')
        ''' Actual value was > 0.
    End Function

    Private Function ValueConstant(i As Integer) As Boolean
        Return i Is 5
    End Function
End Class

Stack traces trimmed for readability. NegatedDeclaration loses its whole body, because the throw comes from the hoisting path in CommonConversions.ConvertToVariableDeclaratorOrNull rather than from the visitor.

ValueConstant is the case worth separating: no error is reported, and Is compares references in VB, so i Is 5 does not compile against a value type. The others at least say something.

Expected output
Friend Class Picture
End Class

Friend Class TestClass
    Private Function NegatedType(o As Object) As Boolean
        Return TypeOf o IsNot String
    End Function

    Private Function NegatedNamedType(o As Object) As Boolean
        Return TypeOf o IsNot Picture
    End Function

    Private Function NegatedDeclaration(o As Object) As Integer
        Dim s As String = Nothing
        If CSharpImpl.__Assign(s, TryCast(o, String)) Is Nothing Then Return -1
        Return s.Length
    End Function

    Private Function Relational(i As Integer) As Boolean
        Return i > 0
    End Function

    Private Function ValueConstant(i As Integer) As Boolean
        Return i = 5
    End Function
End Class

VisitIsPatternExpression handles only DeclarationPatternSyntax and ConstantPatternSyntax and throws for anything else, so type patterns, negated patterns and relational patterns all fail. They have direct VB equivalents, so these read as gaps rather than language differences.

Details
  • Product in use: the NuGet library, called through ProjectConversion.ConvertSingleAsync.
  • Version in use: master at 26060772. Also reproduces on NuGet 10.0.1.923
  • Did you see it working in a previous version, which? No
  • Any other relevant information to the issue, or your interest in contributing a fix.
    I have a branch with the fix and six characterization tests, full suite green: https://github.com/gherards99/CodeConverter/tree/vb-pattern-matching

Two related gaps are deliberately left out of it, since both need the tested expression evaluated once rather than repeated, which means introducing a temporary: property patterns (o is T { P: true }, l is { Count: > 0 }, same ArgumentOutOfRangeException) and ??= (NotSupportedException: CoalesceAssignmentExpression is not supported!). I would rather raise those separately if you agree with the approach here.

Target-typed new is #1112 and the branch covers it too. The branch also makes #983 report the failure instead of silently returning nothing.

主要言語
C#
スター
913
フォーク
244
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

icsharpcode/CodeConverter のほかの issue

icsharpcode/CodeConverter の issue をすべて見る

似ている issue

C# の issue をもっと見る

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

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