mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
When a null literal is the only argument a generic type argument could be inferred from, and that type argument is an anonymous type, ILSpy used to drop the type arguments entirely (they cannot be written explicitly), producing 'Test(null)', which no longer compiles (CS0411). A conditional expression whose never-taken branch creates an instance of the anonymous type is the minimal C# expression that gives a null value that type, so the argument now carries enough information for type inference. The instance expression is obtained by translating a synthesized 'newobj' with 'default.value' arguments through the existing pipeline rather than assembling syntax by hand; the property values are typed defaults, since the IL only contains ldnull. Anonymous types occurring inside other constructed types (e.g. arrays) stay unexpressible and keep the previous output. Assisted-by: Claude:claude-fable-5:Claude Codepull/3878/head
2 changed files with 109 additions and 3 deletions
Loading…
Reference in new issue