mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
CachedDelegateInitializationWithField only fired when the instruction after the caching `if` read the cache field exactly once. A discarded conversion -- `_ = (Action<int>)M;` -- reads it zero times: Roslyn emits the null check and the store, and nothing else. The transform bailed out, so the `<>O` cache class and its `<0>__M` field survived into the output under names no C# compiler will accept. Zero usages is now handled: the `if` is replaced by the delegate construction it guarded, which is what the source expressed, and the caching disappears with the field. The rest of the method is checked for loads of the same field first, since only then is this `if` the sole initialization. Closes #3965pull/4133/head
3 changed files with 50 additions and 4 deletions
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty |
||||
{ |
||||
internal class Issue3965 |
||||
{ |
||||
private static void M(int x) |
||||
{ |
||||
} |
||||
|
||||
private static void Use(Action<int> action) |
||||
{ |
||||
} |
||||
|
||||
public static void DiscardedMethodGroupConversion() |
||||
{ |
||||
#if EXPECTED_OUTPUT
|
||||
new Action<int>(M); |
||||
#else
|
||||
_ = (Action<int>)M; |
||||
#endif
|
||||
} |
||||
|
||||
public static void UsedMethodGroupConversion() |
||||
{ |
||||
Use(M); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue