Skip to content

Commit 24c708b

Browse files
Merge pull request #311 from mrmonday/misc-fixes
Miscellaneous fixes
2 parents 91867c2 + 07ffb2f commit 24c708b

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

ICSharpCode.CodeConverter/CSharp/NodesVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ private bool NeedsVariableForArgument(VBSyntax.SimpleArgumentSyntax node)
14741474
bool isUsing = symbolInfo?.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax()?.Parent?.Parent?.IsKind(VBasic.SyntaxKind.UsingStatement) == true;
14751475

14761476
var typeInfo = _semanticModel.GetTypeInfo(node.Expression);
1477-
bool isTypeMismatch = !typeInfo.Type.Equals(typeInfo.ConvertedType);
1477+
bool isTypeMismatch = typeInfo.Type == null || !typeInfo.Type.Equals(typeInfo.ConvertedType);
14781478

14791479
return (!isIdentifier && !isMemberAccess) || isProperty || isTypeMismatch || isUsing;
14801480
}

ICSharpCode.CodeConverter/CSharp/TypeConversionAnalyzer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ private TypeConversionKind AnalyzeConversion(Microsoft.CodeAnalysis.VisualBasic.
105105
}
106106
return TypeConversionKind.Implicit;
107107
}
108+
else if (csConversion.IsExplicit && csConversion.IsEnumeration)
109+
{
110+
return TypeConversionKind.Implicit;
111+
}
108112
else if (csConversion.IsExplicit && vbConversion.IsNumeric && vbType.TypeKind != TypeKind.Enum)
109113
{
110114
return TypeConversionKind.Explicit;

Tests/CSharp/ExpressionTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ ElseIf Bar(True = False) Then
230230
End If
231231
End Sub
232232
233+
Sub Foo5()
234+
Bar(Nothing)
235+
End Sub
236+
233237
Sub Bar(ByRef b As Boolean)
234238
End Sub
235239
@@ -290,6 +294,12 @@ public void Foo4()
290294
}
291295
}
292296
297+
public void Foo5()
298+
{
299+
var argb = default(bool);
300+
Bar(ref argb);
301+
}
302+
293303
public void Bar(ref bool b)
294304
{
295305
}
@@ -397,6 +407,34 @@ public void Bar(int x)
397407
}");
398408
}
399409

410+
[Fact]
411+
public void IntToEnumArg()
412+
{
413+
TestConversionVisualBasicToCSharpWithoutComments(@"Public Class Class1
414+
Sub Foo(ByVal arg As TriState)
415+
End Sub
416+
417+
Sub Main()
418+
Foo(0)
419+
End Sub
420+
End Class",
421+
@"using Microsoft.VisualBasic;
422+
423+
public class Class1
424+
{
425+
public void Foo(TriState arg)
426+
{
427+
}
428+
429+
public void Main()
430+
{
431+
Foo((TriState)0);
432+
}
433+
}");
434+
}
435+
436+
437+
400438
[Fact]
401439
public void EnumSwitch()
402440
{

0 commit comments

Comments
 (0)