Skip to content
Permalink
Browse files

Fix aliased imports with type names

  • Loading branch information
mrmonday committed Nov 13, 2019
1 parent 6f749da commit b17bebc9bb98270910c43d29c32c8896e7a26f77
Showing with 24 additions and 7 deletions.
  1. +4 −1 ICSharpCode.CodeConverter/CSharp/ExpressionNodeVisitor.cs
  2. +20 −6 Tests/CSharp/ExpressionTests.cs
@@ -868,7 +868,6 @@ public override async Task<CSharpSyntaxNode> VisitIdentifierName(VBasic.Syntax.I

var qualifiedIdentifier = !node.Parent.IsKind(VBasic.SyntaxKind.SimpleMemberAccessExpression, VBasic.SyntaxKind.QualifiedName, VBasic.SyntaxKind.NameColonEquals, VBasic.SyntaxKind.ImportsStatement, VBasic.SyntaxKind.NamespaceStatement, VBasic.SyntaxKind.NamedFieldInitializer)
|| node.Parent is VBasic.Syntax.MemberAccessExpressionSyntax maes && maes.Expression == node
|| node.Parent is VBasic.Syntax.QualifiedNameSyntax qns && qns.Left == node
? QualifyNode(node, identifier) : identifier;

var withArgList = AddEmptyArgumentListIfImplicit(node, qualifiedIdentifier);
@@ -889,6 +888,10 @@ public override async Task<CSharpSyntaxNode> VisitIdentifierName(VBasic.Syntax.I

public override async Task<CSharpSyntaxNode> VisitQualifiedName(VBasic.Syntax.QualifiedNameSyntax node)
{
var symbol = GetSymbolInfoInDocument(node);
if (symbol != null && symbol.IsType()) {
return CommonConversions.GetTypeSyntax(symbol.GetSymbolType());
}
var lhsSyntax = (NameSyntax) await node.Left.AcceptAsync(TriviaConvertingVisitor);
var rhsSyntax = (SimpleNameSyntax) await node.Right.AcceptAsync(TriviaConvertingVisitor);

@@ -2302,34 +2302,48 @@ public void Foo()
[Fact]
public async Task AliasedImportsWithTypePromotionIssue401()
{
await TestConversionVisualBasicToCSharp(
await TestConversionVisualBasicToCSharpWithoutComments(
@"Imports System.IO
Imports SIO = System.IO
Imports Microsoft.VisualBasic
Imports VB = Microsoft.VisualBasic
Public Class Test
Private aliased As String = VB.Left(""SomeText"", 1)
Private aliased2 As System.Delegate = SIO.ErrorEventHandler
Private aliased2 As System.Delegate = New SIO.ErrorEventHandler(AddressOf OnError)
' Make use of the non-aliased imports, but ensure there's a name clash that requires the aliases in the above case
Private ErrorEventHandler As String = NameOf(TextReader)
Private Tr As String = NameOf(TextReader)
Private Strings As String = NameOf(VBCodeProvider)
Class ErrorEventHandler
End Class
Shared Sub OnError(s As Object, e As ErrorEventArgs)
End Sub
End Class",
@"using System;
using System.IO;
using SIO = System.IO;
using Microsoft.VisualBasic;
using SIO = System.IO;
using VB = Microsoft.VisualBasic;
public partial class Test
{
private string aliased = VB.Strings.Left(""SomeText"", 1);
private Delegate aliased2 = SIO.ErrorEventHandler;
private Delegate aliased2 = new SIO.ErrorEventHandler(OnError);
// Make use of the non-aliased imports, but ensure there's a name clash that requires the aliases in the above case
private string ErrorEventHandler = nameof(TextReader);
private string Tr = nameof(TextReader);
private string Strings = nameof(VBCodeProvider);
public partial class ErrorEventHandler
{
}
public static void OnError(object s, ErrorEventArgs e)
{
}
}");
}

0 comments on commit b17bebc

Please sign in to comment.
You can’t perform that action at this time.