From f5db45eaf34adaf2d0bfdcfea7dc825db16c30d0 Mon Sep 17 00:00:00 2001 From: Daniel Abrahamsson Date: Tue, 17 Nov 2020 10:40:27 +0100 Subject: [PATCH 1/2] Ensure methods of Object are also available on interface objects --- src/runtime/classmanager.cs | 11 +++++++++++ src/tests/test_interface.py | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/runtime/classmanager.cs b/src/runtime/classmanager.cs index 26d0536ab..c8bed6bc4 100644 --- a/src/runtime/classmanager.cs +++ b/src/runtime/classmanager.cs @@ -341,6 +341,17 @@ private static ClassInfo GetClassInfo(Type type) } } } + + // All interface implementations inherit from Object, + // but GetMembers don't return them either. + var objFlags = BindingFlags.Public | BindingFlags.Instance; + foreach (var mi in typeof(object).GetMembers(objFlags)) + { + if (local[mi.Name] == null) + { + items.Add(mi); + } + } } for (i = 0; i < items.Count; i++) diff --git a/src/tests/test_interface.py b/src/tests/test_interface.py index 4546471f2..130bd71c1 100644 --- a/src/tests/test_interface.py +++ b/src/tests/test_interface.py @@ -136,3 +136,14 @@ def test_interface_collection_iteration(): untyped_list.Add(elem) for e in untyped_list: assert type(e).__name__ == "int" + + +def test_methods_of_Object_are_available(): + """Test calling methods inherited from Object""" + import System + clrVal = System.Int32(100) + i = System.IComparable(clrVal) + assert i.Equals(clrVal) + assert clrVal.GetHashCode() == i.GetHashCode() + assert clrVal.GetType() == i.GetType() + assert clrVal.ToString() == i.ToString() From 3aae82951afc67c1c43cb24aa900b563c62d5a80 Mon Sep 17 00:00:00 2001 From: Daniel Abrahamsson Date: Tue, 17 Nov 2020 21:00:18 +0100 Subject: [PATCH 2/2] Add change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f6185b61..0da350cef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ details about the cause of the failure - Indexers can now be used with interface objects - Fixed a bug where indexers could not be used if they were inherited - Made it possible to use `__len__` also on `ICollection<>` interface objects +- Made it possible to call `ToString`, `GetHashCode`, and `GetType` on inteface objects ### Removed