diff --git a/ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs b/ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs index 06f07cdd9..04ce3ef8f 100644 --- a/ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs +++ b/ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs @@ -104,10 +104,6 @@ namespace ICSharpCode.Decompiler.TypeSystem /// NullabilityAnnotations = 0x400, /// - /// If this option is active, - /// - LocalFunctions = 0x800, - /// /// Default settings: typical options for the decompiler, with all C# languages features enabled. /// Default = Dynamic | Tuple | ExtensionMethods | DecimalConstants | ReadOnlyStructsAndParameters diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/LocalFunctionMethod.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/LocalFunctionMethod.cs index be3201461..6a42b4364 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/LocalFunctionMethod.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/LocalFunctionMethod.cs @@ -41,21 +41,22 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation { if (!(obj is LocalFunctionMethod other)) return false; - return baseMethod.Equals(other.baseMethod, typeNormalization); + return baseMethod.Equals(other.baseMethod, typeNormalization) + && NumberOfCompilerGeneratedParameters == other.NumberOfCompilerGeneratedParameters; } public override bool Equals(object obj) { - var other = obj as LocalFunctionMethod; - if (other == null) + if (!(obj is LocalFunctionMethod other)) return false; - return baseMethod.Equals(other.baseMethod); + return baseMethod.Equals(other.baseMethod) + && NumberOfCompilerGeneratedParameters == other.NumberOfCompilerGeneratedParameters; } public override int GetHashCode() { unchecked { - return baseMethod.GetHashCode() + 1; + return baseMethod.GetHashCode() + NumberOfCompilerGeneratedParameters + 1; } } @@ -66,13 +67,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation internal int NumberOfCompilerGeneratedParameters { get; } - public IMember MemberDefinition { - get { - if (baseMethod.MemberDefinition == baseMethod) - return this; - return new LocalFunctionMethod((IMethod)baseMethod.MemberDefinition, NumberOfCompilerGeneratedParameters); - } - } + public IMember MemberDefinition => this; public IType ReturnType => baseMethod.ReturnType; IEnumerable IMember.ExplicitlyImplementedInterfaceMembers => baseMethod.ExplicitlyImplementedInterfaceMembers; @@ -122,6 +117,10 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation IEnumerable IEntity.GetAttributes() => baseMethod.GetAttributes(); IEnumerable IMethod.GetReturnTypeAttributes() => baseMethod.GetReturnTypeAttributes(); bool IMethod.ReturnTypeIsRefReadOnly => baseMethod.ReturnTypeIsRefReadOnly; + /// + /// We consider local functions as always static, because they do not have a "this parameter". + /// Even local functions in instance methods capture this. + /// public bool IsStatic => true; public bool IsAbstract => baseMethod.IsAbstract; public bool IsSealed => baseMethod.IsSealed; diff --git a/ICSharpCode.Decompiler/TypeSystem/VarArgInstanceMethod.cs b/ICSharpCode.Decompiler/TypeSystem/VarArgInstanceMethod.cs index d88900caf..a151d1464 100644 --- a/ICSharpCode.Decompiler/TypeSystem/VarArgInstanceMethod.cs +++ b/ICSharpCode.Decompiler/TypeSystem/VarArgInstanceMethod.cs @@ -129,7 +129,9 @@ namespace ICSharpCode.Decompiler.TypeSystem get { return baseMethod.IsExtensionMethod; } } - bool IMethod.IsLocalFunction => false; + bool IMethod.IsLocalFunction { + get { return baseMethod.IsLocalFunction; } + } public bool IsConstructor { get { return baseMethod.IsConstructor; }