CodeConverter icon indicating copy to clipboard operation
CodeConverter copied to clipboard

VB -> C#: Invoking extension method uses base accessor instead of this.

Open Yozer opened this issue 2 years ago • 0 comments

VB.Net input code

Module StringExtensions
    <Extension>
    Public Sub Print(x As ITest)
    End Sub

  Public Interface ITest
  End Interface
  
  Public Class Test
      Implements ITest
      Public Sub Method()
          Print()
      End Sub
  End Class
End Module

Erroneous output

public void Method()
{
    base.Print();
}

Expected output

public void Method()
{
    this.Print();
}

When the extension method is defined without an interface:

Public Sub Print(x As Test)

Then the converted code correctly uses this.

Details

  • Product in use: e.g. VS extension
  • Version in use: e.g. 5.6.3 or a commit hash ac307905bf3e494caa2c98b9739c678a5faf4c17
  • Did you see it working in a previous version, which?
  • Any other relevant information to the issue, or your interest in contributing a fix.

This is a weird one. The vb member access node is actually seen as MyBase.Print() image

And the invocation symbol cannot be found (it's null) image

Interestingly sharblab.io doesn't even show MyBase symbol in the syntax tree. IL code uses this (using base isn't allowed). Could it be a bug in roslyn?

Yozer avatar Feb 12 '22 22:02 Yozer