Regex sourcegen fails with CS0759 when member inside file scoped class

Đang mở
#136,754 1 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ó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp
Lĩnh vực
compilers

Hướng nghiên cứu

The payload gives a reproduction using the GeneratedRegex attribute on a partial method inside a static file partial class, which produces CS0759. Start by reproducing it with that snippet and finding where the regex source generator emits the partial method implementation. Done means a clearer diagnostic for file-scoped containing types, or a documented limitation, with a test covering the case.

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

Mô tả

area-System.Text.RegularExpressions untriaged
Description

like for #57880 the regex source generator errors out with "No defining declaration found for implementing declaration of partial method", which is technically right, just that maybe a more to the point error message could help finding out that this can't work with a file scoped class

Reproduction Steps
static file partial class sfpc
{
    [GeneratedRegex("[^a-zA-Z0-9\\.\\-_]", RegexOptions.Compiled | RegexOptions.ECMAScript)]
    private static partial Regex GetSanitizeRx();
}
Expected behavior

warn user about file scoped class

Actual behavior

error CS0759

Regression?

i don't think so, it's the same on net7 and net10

Known Workarounds

No response

Configuration

windows up to date, vs up to date, x64

Other information

No response

Ngôn ngữ chính
C#
Star
18.4k
Fork
5.8k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
588

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

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

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 dotnet/runtime

Tất cả issue của dotnet/runtime

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.