From 77385d4904ced2a31e73f172c544201cacc063b3 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 1 Nov 2019 23:05:40 +0100 Subject: [PATCH] #1773: Remove copies of parameter values only if the types match exactly. --- .../TestCases/Pretty/DelegateConstruction.cs | 6 ++++++ .../IL/Transforms/TransformDisplayClassUsage.cs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs index 2409c65a91..7f80f24771 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs @@ -385,5 +385,11 @@ public static Func CapturedTypeParameter2(TN return captured.FirstOrDefault(); }; } + + public static Func Issue1773(short data) + { + int integerData = data; + return () => integerData; + } } } diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformDisplayClassUsage.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformDisplayClassUsage.cs index 7289797078..3338022779 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformDisplayClassUsage.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformDisplayClassUsage.cs @@ -314,7 +314,7 @@ protected internal override void VisitStObj(StObj inst) } else { // This is an uninitialized variable: ILInstruction value; - if (inst.Value.MatchLdLoc(out var v) && v.Kind == VariableKind.Parameter && currentFunction == v.Function) { + if (inst.Value.MatchLdLoc(out var v) && v.Kind == VariableKind.Parameter && currentFunction == v.Function && v.Type.Equals(fieldType)) { // Special case for parameters: remove copies of parameter values. instructionsToRemove.Add(inst); value = inst.Value;