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

Đang mở
#835 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
compilers, tooling

Hướng nghiên cứu

Bắt đầu với đầu vào VB và so sánh C# được tạo ra với đầu ra mong đợi; sau đó kiểm tra hành vi đã được báo cáo của Roslyn đối với member-access và invocation-symbol. Sử dụng các quan sát về syntax-tree và IL để xác định đường dẫn của converter có liên quan; hoàn tất khi lời gọi extension dựa trên interface phát ra this.Print() thay vì base.Print().

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
C#
Star
918
Fork
244
Merge trung bình
1 ngày 10 giờ
Pull request đã merge (30 ngày)
29

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của icsharpcode/CodeConverter

Tất cả issue của icsharpcode/CodeConverter

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.