Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CodeConverter/CSharp/LambdaConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public async Task<CSharpSyntaxNode> ConvertAsync(VBSyntax.LambdaExpressionSyntax
BlockSyntax block = null;
ExpressionSyntax expressionBody = null;
ArrowExpressionClauseSyntax arrow = null;
if (!convertedStatements.TryUnpackSingleStatement(out StatementSyntax singleStatement)) {
bool hasComments = vbNode.DescendantTrivia().Any(t => t.IsKind(VBasic.SyntaxKind.CommentTrivia));
if (hasComments || !convertedStatements.TryUnpackSingleStatement(out StatementSyntax singleStatement)) {
convertedStatements = convertedStatements.Select(l => l.WithTrailingTrivia(SyntaxFactory.ElasticCarriageReturnLineFeed)).ToList();
block = SyntaxFactory.Block(convertedStatements);
} else if (singleStatement.TryUnpackSingleExpressionFromStatement(out expressionBody)) {
Expand Down
48 changes: 47 additions & 1 deletion Tests/CSharp/ExpressionTests/ExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2931,4 +2931,50 @@ public object Edit(bool flag2 = false, CrashEnum? crashEnum = default)
}
}");
}
}
[Fact]
public async Task LambdaBodyExpressionWithCommentsAsync() {
await TestConversionVisualBasicToCSharpAsync(@"
Imports System.Threading.Tasks
Imports System.Collections.Generic

Public Class ConversionTest1
Public Sub BugRepro()
Dim dt As New List(Of Integer)

Parallel.ForEach(dt, Sub(row)
If Not String.IsNullOrWhiteSpace("""") Then
'comment1
Dim test1 As Boolean = True
'comment2
Dim test2 As Boolean = True
'comment3
Dim test3 As Boolean = True
End If
End Sub)
End Sub
End Class
", @"using System.Collections.Generic;
using System.Threading.Tasks;

public partial class ConversionTest1
{
public void BugRepro()
{
var dt = new List<int>();

Parallel.ForEach(dt, row =>
{
if (!string.IsNullOrWhiteSpace(""""))
{
// comment1
bool test1 = true;
// comment2
bool test2 = true;
// comment3
bool test3 = true;
}
});
}
}", incompatibleWithAutomatedCommentTesting: true);
}
}
Loading