Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change for issue #373. Multiple declaration with implicit type. #385

Merged
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
2 changes: 1 addition & 1 deletion ICSharpCode.CodeConverter/CSharp/CommonConversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public CommonConversions(Document document, SemanticModel semanticModel,
foreach (var name in declarator.Names) {
var declaredSymbol = _semanticModel.GetDeclaredSymbol(name);
var declaredSymbolType = declaredSymbol.GetSymbolType();
var requireExplicitType = requireExplicitTypeForAll || vbInitializerType != null && !Equals(declaredSymbolType, vbInitializerType);
var requireExplicitType = requireExplicitTypeForAll || vbInitializerType != null && !Equals(declaredSymbolType, vbInitializerType) || declarator.Names.Count>1 && name.SpanStart == declarator.SpanStart;
var csTypeSyntax = (TypeSyntax)GetTypeSyntax(declaredSymbolType);

bool isField = declarator.Parent.IsKind(SyntaxKind.FieldDeclaration);
Expand Down
26 changes: 24 additions & 2 deletions Tests/CSharp/StatementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,29 @@ private void TestMethod()
}
}");
}
[Fact]
public async Task DeclarationStatementTwoVariables()
{
await TestConversionVisualBasicToCSharpWithoutComments(
@"Class Test
Private Sub TestMethod()
Dim x, y As Date
Console.WriteLine(x)
Console.WriteLine(y)
End Sub
End Class", @"using System;

internal partial class Test
{
private void TestMethod()
{
DateTime x = default(DateTime), y = default(DateTime);
Console.WriteLine(x);
Console.WriteLine(y);
}
}");
}

[Theory]
[InlineData("Sub", "", "void")]
[InlineData("Function", " As Long", "long")]
Expand Down Expand Up @@ -1334,7 +1356,7 @@ End Sub
{
private void TestMethod(int end)
{
var b = default(int[]), s = default(int[]);
int[] b = default(int[]), s = default(int[]);
for (int i = 0, loopTo = end; i <= loopTo; i++)
b[i] = s[i];
}
Expand Down Expand Up @@ -1410,7 +1432,7 @@ End Sub
{
private void TestMethod(int end)
{
var b = default(int[]), s = default(int[]);
int[] b = default(int[]), s = default(int[]);
for (int i = 0, loopTo = end - 1; i <= loopTo; i++)
b[i] = s[i];
}
Expand Down