mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
* Fix anonymous-type lambda early-return emitting unresolvable cast When a lambda's inferred return type contains an anonymous type and one branch returns null, the decompiler emitted an explicit cast such as `return (IEnumerable<<>f__AnonymousType0<int>>)null;`, which is invalid C#. Skip the cast in IsPossibleLossOfTypeInformation for null literals whenever the expected type contains an anonymous type: null is implicitly convertible to any reference type, so no cast is needed, and the anonymous type has no nameable form to cast to anyway. Fixes #3751pull/3763/head
3 changed files with 49 additions and 13 deletions
@ -0,0 +1,28 @@ |
|||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty |
||||||
|
{ |
||||||
|
internal class Issue3751 |
||||||
|
{ |
||||||
|
private static bool Cond; |
||||||
|
|
||||||
|
private static T Infer<T>(Func<T> factory) |
||||||
|
{ |
||||||
|
return factory(); |
||||||
|
} |
||||||
|
|
||||||
|
public object Trigger() |
||||||
|
{ |
||||||
|
return Infer(delegate { |
||||||
|
if (Cond) |
||||||
|
{ |
||||||
|
Console.WriteLine(); |
||||||
|
return null; |
||||||
|
} |
||||||
|
return new { |
||||||
|
Value = 1 |
||||||
|
}; |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue