Browse Source

Fix #2282: Finalizers must be void and cannot be declared in interfaces

pull/2301/head
Siegfried Pammer 5 years ago
parent
commit
fdda8abd74
  1. 9
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InterfaceTests.cs
  2. 10
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  3. 4
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs

9
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InterfaceTests.cs

@ -97,10 +97,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
remove { remove {
} }
} }
public int Finalize()
{
return 0;
}
void IA.Method() void IA.Method()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }
internal interface IInterfacesCannotDeclareDtors
{
int Finalize();
}
} }
} }

10
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -1127,9 +1127,13 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
// A method introduced in a class or struct hides all non-method base class members with the same name, and all // A method introduced in a class or struct hides all non-method base class members with the same name, and all
// base class methods with the same signature (method name and parameter count, modifiers, and types). // base class methods with the same signature (method name and parameter count, modifiers, and types).
if (baseType.GetMembers(m => m.SymbolKind != SymbolKind.Indexer && m.Name == entity.Name && lookup.IsAccessible(m, true)) if (baseType.GetMembers(m => m.SymbolKind != SymbolKind.Indexer
.Any(m => m.SymbolKind != SymbolKind.Method || (((IMethod)entity).TypeParameters.Count == ((IMethod)m).TypeParameters.Count && m.SymbolKind != SymbolKind.Constructor
&& parameterListComparer.Equals(((IMethod)entity).Parameters, ((IMethod)m).Parameters)))) && m.SymbolKind != SymbolKind.Destructor
&& m.Name == entity.Name && lookup.IsAccessible(m, true))
.Any(m => m.SymbolKind != SymbolKind.Method ||
(((IMethod)entity).TypeParameters.Count == ((IMethod)m).TypeParameters.Count
&& parameterListComparer.Equals(((IMethod)entity).Parameters, ((IMethod)m).Parameters))))
{ {
return true; return true;
} }

4
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs

@ -82,8 +82,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
} }
else if ((attributes & finalizerAttributes) == finalizerAttributes) else if ((attributes & finalizerAttributes) == finalizerAttributes)
{ {
string name = this.Name; if (Name == "Finalize" && Parameters.Count == 0 && ReturnType.IsKnownType(KnownTypeCode.Void)
if (name == "Finalize" && Parameters.Count == 0) && (DeclaringTypeDefinition as MetadataTypeDefinition)?.Kind == TypeKind.Class)
{ {
this.symbolKind = SymbolKind.Destructor; this.symbolKind = SymbolKind.Destructor;
} }

Loading…
Cancel
Save