From 40b6f0c7bf7a776538efab540b82d4ec7f7fdf65 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 9 Mar 2019 21:32:03 +0100 Subject: [PATCH] Use appropriate type for helper variables introduced for named arguments. --- .../IL/Instructions/ILFunction.cs | 13 ++++++++++++- .../IL/Transforms/NamedArgumentTransform.cs | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs b/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs index cbebd1c14f..339218582e 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs @@ -229,7 +229,18 @@ public void RunTransforms(IEnumerable transforms, ILTransformConte public ILVariable RegisterVariable(VariableKind kind, IType type, string name = null) { - var variable = new ILVariable(kind, type); + return RegisterVariable(kind, type, type.GetStackType(), name); + } + + public ILVariable RegisterVariable(VariableKind kind, StackType stackType, string name = null) + { + var type = Method.Compilation.FindType(stackType.ToKnownTypeCode()); + return RegisterVariable(kind, type, stackType, name); + } + + ILVariable RegisterVariable(VariableKind kind, IType type, StackType stackType, string name = null) + { + var variable = new ILVariable(kind, type, stackType); if (string.IsNullOrWhiteSpace(name)) { name = "I_" + (helperVariableCount++); variable.HasGeneratedName = true; diff --git a/ICSharpCode.Decompiler/IL/Transforms/NamedArgumentTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/NamedArgumentTransform.cs index 1c41a7c834..fb9bb125ad 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/NamedArgumentTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/NamedArgumentTransform.cs @@ -79,7 +79,7 @@ internal static void IntroduceNamedArgument(ILInstruction arg, ILTransformContex { var call = (CallInstruction)arg.Parent; Debug.Assert(context.Function == call.Ancestors.OfType().First()); - var v = context.Function.RegisterVariable(VariableKind.NamedArgument, arg.InferType(context.TypeSystem)); + var v = context.Function.RegisterVariable(VariableKind.NamedArgument, arg.ResultType); context.Step($"Introduce named argument '{v.Name}'", arg); if (!(call.Parent is Block namedArgBlock) || namedArgBlock.Kind != BlockKind.CallWithNamedArgs) { // create namedArgBlock: