diff --git a/ICSharpCode.Decompiler.Tests/DataFlowTest.cs b/ICSharpCode.Decompiler.Tests/DataFlowTest.cs index 3c599ccc2..8c49c3949 100644 --- a/ICSharpCode.Decompiler.Tests/DataFlowTest.cs +++ b/ICSharpCode.Decompiler.Tests/DataFlowTest.cs @@ -55,10 +55,14 @@ namespace ICSharpCode.Decompiler.Tests public void TryFinallyWithAssignmentInFinally() { ILVariable v = new ILVariable(VariableKind.Local, SpecialType.UnknownType, 0); - ILFunction f = new ILFunction((IMethod)null, 0, new GenericContext(), new TryFinally( - new Nop(), - new StLoc(v, new LdcI4(0)) - )); + ILFunction f = new ILFunction( + returnType: SpecialType.UnknownType, + parameters: new IParameter[0], + genericContext: new GenericContext(), + body: new TryFinally( + new Nop(), + new StLoc(v, new LdcI4(0)) + )); f.AddRef(); f.Variables.Add(v); f.Body.AcceptVisitor(new RDTest(f, v)); diff --git a/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs b/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs index daaeb214a..d66248133 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs @@ -166,13 +166,11 @@ namespace ICSharpCode.Decompiler.IL /// /// Return type of this function. - /// Might be null, if this function was not created from metadata. /// public readonly IType ReturnType; /// /// List of parameters of this function. - /// Might be null, if this function was not created from metadata. /// public readonly IReadOnlyList Parameters; @@ -188,17 +186,16 @@ namespace ICSharpCode.Decompiler.IL /// /// /// Use to create ILAst. - /// may be null. /// public ILFunction(IMethod method, int codeSize, GenericContext genericContext, ILInstruction body, ILFunctionKind kind = ILFunctionKind.TopLevelFunction) : base(OpCode.ILFunction) { this.Method = method; - this.Name = Method?.Name; + this.Name = method.Name; this.CodeSize = codeSize; this.GenericContext = genericContext; this.Body = body; - this.ReturnType = Method?.ReturnType; - this.Parameters = Method?.Parameters; + this.ReturnType = method.ReturnType; + this.Parameters = method.Parameters; this.Variables = new ILVariableCollection(this); this.LocalFunctions = new InstructionCollection(this, 1); this.kind = kind; @@ -207,15 +204,15 @@ namespace ICSharpCode.Decompiler.IL /// /// This constructor is only to be used by the TransformExpressionTrees step. /// - internal ILFunction(IType returnType, IReadOnlyList parameters, GenericContext genericContext, ILInstruction body) : base(OpCode.ILFunction) + internal ILFunction(IType returnType, IReadOnlyList parameters, GenericContext genericContext, ILInstruction body, ILFunctionKind kind = ILFunctionKind.TopLevelFunction) : base(OpCode.ILFunction) { this.GenericContext = genericContext; this.Body = body; - this.ReturnType = returnType; - this.Parameters = parameters; + this.ReturnType = returnType ?? throw new ArgumentNullException(nameof(returnType)); + this.Parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); this.Variables = new ILVariableCollection(this); this.LocalFunctions = new InstructionCollection(this, 1); - this.kind = ILFunctionKind.ExpressionTree; + this.kind = kind; } internal override void CheckInvariant(ILPhase phase) diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs index 4ed88e0c7..725bce082 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs @@ -156,8 +156,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms var container = new BlockContainer(); container.AddILRange(instruction); var functionType = instruction.Method.ReturnType.TypeArguments[0]; - var returnType = functionType.GetDelegateInvokeMethod()?.ReturnType; - var function = new ILFunction(returnType, parameterList, context.Function.GenericContext, container); + var returnType = functionType.GetDelegateInvokeMethod()?.ReturnType ?? SpecialType.UnknownType; + var function = new ILFunction(returnType, parameterList, context.Function.GenericContext, container, ILFunctionKind.ExpressionTree); function.DelegateType = functionType; function.Kind = IsExpressionTree(functionType) ? ILFunctionKind.ExpressionTree : ILFunctionKind.Delegate; function.Variables.AddRange(parameterVariablesList);