Regex sourcegen fails with CS0759 when member inside file scoped class

Aperta
#136,754 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
compilers

Direzione di ricerca

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.

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

Descrizione

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

Lingua principale
C#
Stelle
18.4k
Fork
5.8k
Merge medio
2g 12h
PR unite (30g)
600

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

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

Tutte le issue di dotnet/runtime

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.