Lambda parameter 'params' and default values are dropped below C# 12
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
- 57/100
Direzione di ricerca
Inizia esaminando il commit "Downgrade params and default values to attributes on pre-C# 12 lambdas" del branch chiuso #4004 e il relativo test Ugly, quindi verifica gli esempi con CSharp11_0. Il lavoro è completo quando i valori predefiniti generano gli attributi Optional/DefaultParameterValue al di sotto di C# 12, params continua a essere omesso e un test impedisce la forma ParamArray non valida.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Split out of #4057, which fixes the case where params and parameter default values were printed
on syntax that cannot carry them. Below C# 12 they are now dropped instead, and this issue tracks
that remaining loss.
What happens
public delegate int ParamsDel(params int[] values);
public delegate int OptDel(int x = 42);
public static ParamsDel MakeParams(int seed) => (params int[] values) => values.Length + seed;
public static OptDel MakeOpt(int seed) => (int x = 42) => x + seed;
Decompiled with --languageversion CSharp11_0:
public static ParamsDel MakeParams(int seed)
{
return (int[] values) => values.Length + seed;
}
public static OptDel MakeOpt(int seed)
{
return (int x) => x + seed;
}
Both modifiers are gone. The output still compiles and still binds the way the input did - the
delegate type declares params and the default, and that is what call sites bind against - so
this is a fidelity loss, not a correctness bug. A reader of the C# 11 output cannot tell the
parameter was params or had a default.
The obvious fix only works for one of the two
C# 10 allows attributes on lambda parameters, so the natural repair is to downgrade the modifiers
to the attributes the compiler would have emitted anyway.
That works for the default value. Verified compiling at LangVersion 11:
return ([Optional][DefaultParameterValue(5)] int x) => x * 2;
It does not work for params:
return ([ParamArray] int[] xs) => xs.Length;
// error CS0674: Do not use 'System.ParamArrayAttribute'/
// 'System.Runtime.CompilerServices.ParamCollectionAttribute'. Use the 'params' keyword instead.
CS0674 rejects [ParamArray] on any parameter, and anonymous methods cannot declare params
either (CS1670), so below C# 12 there is no legal way to spell it on the anonymous function at
all. Dropping it may simply be the correct answer for that half.
Worth knowing: the closed #4004 branch (natural-type-lambdas-methods) carries a commit
"Downgrade params and default values to attributes on pre-C# 12 lambdas" which emits exactly the
[ParamArray] form above, with an Ugly test pinning it. That output does not compile, so the
commit should not be lifted as-is if this is picked up.
Suggested scope
- Emit
[Optional]/[DefaultParameterValue]for a default value below C# 12. - Leave
paramsdropped, and pin that with a test so the CS0674 form cannot come back.
Written by an AI agent (Claude) on Siegfried's behalf.
- Lingua principale
- C#
- Stelle
- 27.1k
- Fork
- 3.8k
- Merge medio
- 1g 23h
- PR unite (30g)
- 44
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di icsharpcode/ILSpy
-
AvaloniaEdit Issues to dateApertaExternal UI
Difficoltà 1/5 1-3 ore Idoneità per principianti 75/100
icsharpcode/ILSpy#4284 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
icsharpcode/ILSpy#4357 ·
I maintainer di solito rispondono entro 1 giorno
-
Misdecompilation of a lazy initialization patternForse già presa @siegfriedpammer l’ha presa 5 giorni fa. ApertaBug Decompiler
Difficoltà 4/5 3-5 giorni Idoneità per principianti 20/100
icsharpcode/ILSpy#4349 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
icsharpcode/ILSpy#4343 ·
I maintainer di solito rispondono entro 1 giorno
-
AI
Difficoltà 4/5 1-2 giorni Idoneità per principianti 55/100
icsharpcode/ILSpy#4300 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di icsharpcode/ILSpy
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
umbraco/Umbraco.Automate#612 ·
I maintainer di solito rispondono entro 1 giorno
-
崩溃日志只按 CRLF 分行Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
PCL-Community/PCL-CE#3872 ·
I maintainer di solito rispondono entro 1 giorno
-
type:task ux
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
elsa-workflows/elsa-foundation#5253 ·
I maintainer di solito rispondono entro 1 giorno