VB -> C#: Nullable comparisons in While conditions produce invalid C#
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Start with the VB input and expected C# output in the issue, then trace how the converter handles While conditions and nullable comparisons. Add a regression test for the supplied case, including the parenthesized comparison variant. Done means the generated condition is a non-nullable bool and preserves VB's behavior when either value is Nothing.
索引モデルが issue の本文から書いたものです。
説明
VB.Net input code
Imports System
Class TestClass
Sub TestMethod(startDate As Date?, endDate As Date?)
Dim currentDate = startDate
While currentDate <= endDate
currentDate = currentDate.Value.AddMinutes(1)
End While
End Sub
End Class
Erroneous output
The converted while condition evaluates to bool? rather than bool, producing:
CS0266: Cannot implicitly convert type 'bool?' to 'bool'.
An explicit conversion exists (are you missing a cast?)
Expected output
using System;
internal partial class TestClass
{
public void TestMethod(DateTime? startDate, DateTime? endDate)
{
var currentDate = startDate;
while (currentDate.HasValue && endDate.HasValue && currentDate.Value <= endDate.Value)
currentDate = currentDate.Value.AddMinutes(1d);
}
}
Details
- Product in use: VS extension, built locally from master.
- Version in use: 10.0.1, local development build.
- Did you see it working in a previous version, which? No.
- VB permits nullable comparisons in
Whileconditions. If the condition evaluates toNothing, the loop body is not executed. C# requires a non-nullableboolcondition. - The converter does not recognize
Whileas a context requiring a non-nullable Boolean result, so it preserves the comparison's nullable result instead of treatingNothingas false. - The issue also occurs when the comparison is enclosed in parentheses:
While (currentDate <= endDate).
- 主要言語
- C#
- スター
- 917
- フォーク
- 243
- 平均マージ
- 2日 15時間
- マージ済み PR(30日)
- 9
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
icsharpcode/CodeConverter のほかの issue
-
VB -> C#
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
icsharpcode/CodeConverter#1301 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
icsharpcode/CodeConverter#1271 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
VB -> C#: Generic extension method inference widens element types when using a base-type comparerオープンVB -> C#
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
icsharpcode/CodeConverter#1302 ·
メンテナーはふだん 3 日以内に返信
-
VB -> C#
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
icsharpcode/CodeConverter#1299 ·
メンテナーはふだん 3 日以内に返信
-
VB -> C#
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
icsharpcode/CodeConverter#1298 ·
メンテナーはふだん 3 日以内に返信
icsharpcode/CodeConverter の issue をすべて見る
似ている issue
-
.NET good first issue testing
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
HelloblueAI/HelloblueGK#311 ·
メンテナーはふだん 1 日以内に返信
-
needs-area-label
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 2 日以内に返信
-
State: Needs Discussion
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
getsentry/sentry-dotnet#5876 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
area-Extensions-FileSystem untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dotnet/runtime#136989 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
library-request
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
QuantConnect/Lean#10034 ·
メンテナーはふだん 1 日以内に返信