Summary
When one lambda parameter has an anonymous type, ILSpy correctly omits that parameter's
unnameable type but leaves sibling parameter types explicit. C# requires lambda parameter
types to be either all explicit or all implicit, so the output fails with CS0748.
Input code
Compiled in Release targeting .NET 10.0:
using System;
public static class C
{
private static TValue GetOrCreate<TKey, TValue>(
TKey key,
Func<TKey, int, TValue> factory) => factory(key, 1);
public static int Read()
{
var key = new { Value = 1 };
return GetOrCreate(key, (item, context) => item.Value + context);
}
}
Erroneous output
public static int Read()
{
return GetOrCreate(new
{
Value = 1
}, (item, int context) => item.Value + context);
}
Recompiling this output fails:
error CS0748: Inconsistent lambda parameter usage; parameter types must be all explicit or all implicit
Expected output
Because the anonymous type cannot be named, every parameter should remain implicit:
(item, context) => item.Value + context
Details
- Product in use: ICSharpCode.Decompiler
- Version in use: master
7554c1b0 (11.0.0.9223)
- The repro was verified in an isolated compile, decompile, recompile round trip.
ExpressionBuilder.MakeParameters removes the type only from parameters whose type contains an anonymous type, leaving the remaining parameter declarations explicitly typed.
- I am happy to contribute a fix.
Summary
When one lambda parameter has an anonymous type, ILSpy correctly omits that parameter's
unnameable type but leaves sibling parameter types explicit. C# requires lambda parameter
types to be either all explicit or all implicit, so the output fails with CS0748.
Input code
Compiled in Release targeting .NET 10.0:
Erroneous output
Recompiling this output fails:
Expected output
Because the anonymous type cannot be named, every parameter should remain implicit:
Details
7554c1b0(11.0.0.9223)ExpressionBuilder.MakeParametersremoves the type only from parameters whose type contains an anonymous type, leaving the remaining parameter declarations explicitly typed.