C# -> VB: most pattern matching fails to convert
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
調査の方向性
VisitIsPatternExpression と CommonConversions.ConvertToVariableDeclaratorOrNull の hoisting パスから始め、その後、リンクされたブランチの 6 つの特性テストを確認します。型、否定、関係、および定数パターンが、エラーや無効な Is 比較なしで、示されている VB の同等表現に変換され、完全なテストスイートが引き続きグリーンであれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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 はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
icsharpcode/CodeConverter のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
icsharpcode/CodeConverter#1271 · コメント 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
icsharpcode/CodeConverter#1275 ·
-
VB -> C#
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
icsharpcode/CodeConverter#1273 ·
-
VB -> C#: "Group By Into" Linq queries supressing aggregations ("Into" part) in the converted code オープンDifficult area VB -> C#
難易度 3/5 1〜2日 初心者へのやさしさ 74/100
icsharpcode/CodeConverter#1272 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
icsharpcode/CodeConverter#1270 ·
icsharpcode/CodeConverter の issue をすべて見る
似ている issue
-
effort:S P3 refactor
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
nightscout/nocturne#1532 ·
-
core dependencies
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
C#/.NET Roslyn LSP オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
DotNetNext/SqlSugar#1458 ·