From: Marek Safar Date: Sun, 28 May 2017 11:47:45 +0000 (+0200) Subject: [mcs] Improves imported destructor detection. Fixes #54159 X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=da76a7b803ede003083fafe391d7381af3cecfa0 [mcs] Improves imported destructor detection. Fixes #54159 --- diff --git a/mcs/mcs/import.cs b/mcs/mcs/import.cs index 87ebf6aac54..359a738a555 100644 --- a/mcs/mcs/import.cs +++ b/mcs/mcs/import.cs @@ -414,6 +414,9 @@ namespace Mono.CSharp kind = MemberKind.Constructor; returnType = module.Compiler.BuiltinTypes.Void; } else { + var mi = (MethodInfo)mb; + returnType = ImportType (mi.ReturnType, new DynamicTypeReader (mi.ReturnParameter), declaringType); + // // Detect operators and destructors // @@ -427,7 +430,7 @@ namespace Mono.CSharp kind = MemberKind.Operator; } } - } else if (parameters.IsEmpty && name == Destructor.MetadataName) { + } else if (parameters.IsEmpty && name == Destructor.MetadataName && returnType.Kind == MemberKind.Void) { kind = MemberKind.Destructor; if (declaringType.BuiltinType == BuiltinTypeSpec.Type.Object) { mod &= ~Modifiers.OVERRIDE; @@ -436,9 +439,6 @@ namespace Mono.CSharp } } - var mi = (MethodInfo) mb; - returnType = ImportType (mi.ReturnType, new DynamicTypeReader (mi.ReturnParameter), declaringType); - // Cannot set to OVERRIDE without full hierarchy checks // this flag indicates that the method could be override // but further validation is needed diff --git a/mcs/tests/test-944-lib.cs b/mcs/tests/test-944-lib.cs new file mode 100644 index 00000000000..4c91effce71 --- /dev/null +++ b/mcs/tests/test-944-lib.cs @@ -0,0 +1,9 @@ +// Compiler options: -t:library + +public class Class1 +{ + public byte[] Finalize () + { + return null; + } +} diff --git a/mcs/tests/test-944.cs b/mcs/tests/test-944.cs new file mode 100644 index 00000000000..4aff1f8b6d9 --- /dev/null +++ b/mcs/tests/test-944.cs @@ -0,0 +1,10 @@ +// Compiler options: -r:test-944-lib.dll + +public class Class2 +{ + public static void Main () + { + var writer = new Class1(); + byte[] bytes = writer.Finalize(); + } +} \ No newline at end of file diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml index b06aba48fd5..64f69ccf611 100644 --- a/mcs/tests/ver-il-net_4_x.xml +++ b/mcs/tests/ver-il-net_4_x.xml @@ -52723,6 +52723,16 @@ + + + + 15 + + + 7 + + +