Lambda parameter 'params' and default values are dropped below C# 12
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
首先检查已关闭的 #4004 分支中的 "Downgrade params and default values to attributes on pre-C# 12 lambdas" 提交及其 Ugly 测试,然后使用 CSharp11_0 验证示例。完成意味着在低于 C# 12 时默认值会生成 Optional/DefaultParameterValue 属性,params 仍被删除,并且有一个测试可防止无效的 ParamArray 形式。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- C#
- 星标
- 27.1k
- 派生
- 3.8k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 44
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
icsharpcode/ILSpy 的其他 Issue
-
External UI
难度 1/5 1-3 小时 新手友好度 75/100
icsharpcode/ILSpy#4284 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
icsharpcode/ILSpy#4357 ·
维护者通常 1 天内回复
-
Misdecompilation of a lazy initialization pattern可能已有人在做 @siegfriedpammer 于 5 天前认领。 未关闭Bug Decompiler
难度 4/5 3-5 天 新手友好度 20/100
icsharpcode/ILSpy#4349 ·
维护者通常 1 天内回复
-
Bug
难度 4/5 3-5 天 新手友好度 45/100
icsharpcode/ILSpy#4343 ·
维护者通常 1 天内回复
-
AI
难度 4/5 1-2 天 新手友好度 55/100
icsharpcode/ILSpy#4300 ·
维护者通常 1 天内回复
查看 icsharpcode/ILSpy 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 3 天内回复
-
bug python
难度 1/5 1 小时以内 新手友好度 88/100
ilia-sokolov/OfficeAgent.NET#89 ·
维护者通常 13 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 82/100
juandresrodca/AdminForge#66 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
umbraco/Umbraco.Automate#612 ·
维护者通常 1 天内回复