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

Aperta
#835 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
csharp
Ambito
compilers, tooling

Direzione di ricerca

Inizia dall’input VB e confronta il C# generato con l’output previsto; quindi esamina il comportamento segnalato di Roslyn relativo a member-access e invocation-symbol. Usa le osservazioni su syntax-tree e IL per individuare il percorso del convertitore coinvolto; il lavoro è terminato quando l’invocazione dell’estensione basata sull’interfaccia emette this.Print() invece di base.Print().

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

compilation error VB -> C#
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?

Lingua principale
C#
Stelle
918
Fork
244
Merge medio
1g 10h
PR unite (30g)
29

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di icsharpcode/CodeConverter

Tutte le issue di icsharpcode/CodeConverter

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.