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

VB -> C#: Explicitly qualified global names not translated #375

Closed
mrmonday opened this issue Sep 6, 2019 · 4 comments · Fixed by #414
Closed

VB -> C#: Explicitly qualified global names not translated #375

mrmonday opened this issue Sep 6, 2019 · 4 comments · Fixed by #414
Assignees
Labels
compilation error A bug where the converted output won't compile VB -> C# Specific to VB -> C# conversion

Comments

@mrmonday
Copy link
Contributor

mrmonday commented Sep 6, 2019

For names which can be used globally, eg. Timer, Now, Len, etc, VB allows you to explicitly qualify them as eg. Microsoft.VisualBasic.Timer. The actual symbol is elsewhere, eg. Microsoft.VisualBasic.DateAndTime.Timer. This is not converted correctly.

Input code

Friend Module Module1
    Sub Main()
        Dim x = Microsoft.VisualBasic.Timer
    End Sub
End Module

Erroneous output

namespace ConsoleApp3
{
    internal static class Module1
    {
        public static void Main()
        {
            double x = Microsoft.VisualBasic.Timer;
        }
    }
}

Expected output

using Microsoft.VisualBasic;

namespace ConsoleApp3
{
    internal static class Module1
    {
        public static void Main()
        {
            double x = DateAndTime.Timer;
        }
    }
}

Details

Error:

error CS0234: The type or namespace name 'Timer' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)

Version: master @ 3ffc597

@GrahamTheCoder GrahamTheCoder added compilation error A bug where the converted output won't compile VB -> C# Specific to VB -> C# conversion labels Sep 10, 2019
@GrahamTheCoder
Copy link
Member

The general case of this is supposed to be handled by TryGetTypePromotedModuleSymbol and QualifyNode. In solving this we should remember it's fine to overqualify things and let them be automatically simplified at the end.

GrahamTheCoder added a commit that referenced this issue Oct 6, 2019
* #375 Need type-promoted references to be fixed in C#
* Generate a property/field for each form in the project
* Add merged declarations to the csproj

Fuller implementation of property:

      [EditorBrowsable(EditorBrowsableState.Never)]
      public WinformsDesignerTest m_WinformsDesignerTest;

      public WinformsDesignerTest WinformsDesignerTest
      {
        [DebuggerHidden] get
        {
          this.m_WinformsDesignerTest = MyProject.MyForms.Create__Instance__<WinformsDesignerTest>(this.m_WinformsDesignerTest);
          return this.m_WinformsDesignerTest;
        }
        [DebuggerHidden] set
        {
          if (value == this.m_WinformsDesignerTest)
            return;
          if (value != null)
            throw new ArgumentException("Property can only be set to Nothing");
          this.Dispose__Instance__<WinformsDesignerTest>(ref this.m_WinformsDesignerTest);
        }
      }

There's a similar patter for generating web services
@GrahamTheCoder GrahamTheCoder self-assigned this Oct 14, 2019
@mrmonday
Copy link
Contributor Author

@GrahamTheCoder are you actively working on this? If not, I'll take a shot at it tomorrow.

@GrahamTheCoder
Copy link
Member

Sorry I probably should have unassigned myself while I was away - just got back. I was looking at it briefly yesterday. I'll push my progress and/or unassign myself by tomorrow.

@GrahamTheCoder GrahamTheCoder removed their assignment Nov 11, 2019
@GrahamTheCoder
Copy link
Member

GrahamTheCoder commented Nov 11, 2019

I didn't get around to spending any more time on this, though a few related tidyups went into #406. In QualifyNode I was pretty much going to try to replace a lot of it with just outputting the full name using something like GetFullMetadataName.

Over to you

mrmonday added a commit to mrmonday/CodeConverter that referenced this issue Nov 12, 2019
@mrmonday mrmonday changed the title VB -> C#: Explicitly qualified global names no translated VB -> C#: Explicitly qualified global names not translated Nov 12, 2019
mrmonday added a commit to mrmonday/CodeConverter that referenced this issue Nov 13, 2019
GrahamTheCoder added a commit that referenced this issue Nov 14, 2019
Correctly handle type promoted module symbols [#332, #375, #401]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compilation error A bug where the converted output won't compile VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants