[mcs] Improves imported destructor detection. Fixes #54159
authorMarek Safar <marek.safar@gmail.com>
Sun, 28 May 2017 11:47:45 +0000 (13:47 +0200)
committerMarek Safar <marek.safar@gmail.com>
Sun, 28 May 2017 11:48:42 +0000 (13:48 +0200)
mcs/mcs/import.cs
mcs/tests/test-944-lib.cs [new file with mode: 0644]
mcs/tests/test-944.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_x.xml

index 87ebf6aac54fb54c69fc2239f9033f11e67498d2..359a738a555e788610b317d88b79e87e82ec31e9 100644 (file)
@@ -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 (file)
index 0000000..4c91eff
--- /dev/null
@@ -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 (file)
index 0000000..4aff1f8
--- /dev/null
@@ -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
index b06aba48fd5ead3c9127195304de99dfdf14ce4f..64f69ccf6119d6db2c8495c2181d887e91652ec5 100644 (file)
       </method>
     </type>
   </test>
+  <test name="test-944.cs">
+    <type name="Class2">
+      <method name="Void Main()" attrs="150">
+        <size>15</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-95.cs">
     <type name="X">
       <method name="Int32 Main()" attrs="150">