From 37adb3efc9f7709d4ddead328db755cf8faaac46 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 13 Jun 2017 09:14:17 +0300 Subject: [PATCH] Fixed the binding of indexer overloads when there's more than one class key. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpSources.cs | 2 +- tests/Common/Common.Tests.cs | 8 ++++++++ tests/Common/Common.cpp | 5 +++++ tests/Common/Common.h | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 78d2ec91..03fb730a 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -2998,7 +2998,7 @@ namespace CppSharp.Generators.CSharp identifier.Append(Helpers.GetSuffixFor(specialization)); var overloads = function.Namespace.GetOverloads(function) - .Where(f => f.IsGenerated).ToList(); + .Where(f => f.IsGenerated || f.OperatorKind == CXXOperatorKind.Subscript).ToList(); var index = overloads.IndexOf(function); if (index >= 0) diff --git a/tests/Common/Common.Tests.cs b/tests/Common/Common.Tests.cs index ef940b75..257feab6 100644 --- a/tests/Common/Common.Tests.cs +++ b/tests/Common/Common.Tests.cs @@ -412,11 +412,19 @@ public class CommonTests : GeneratorTestFixture Assert.AreEqual(4, newProperties.Field); newProperties.Field = 5; Assert.AreEqual(5, indexedProperties[(byte) 0].Field); + var bar = new Bar { A = 5 }; indexedProperties[0u] = bar; Assert.That(bar.A, Is.EqualTo(indexedProperties[0u].A)); indexedProperties[(ushort) 0] = bar; Assert.That(bar.A, Is.EqualTo(indexedProperties[(ushort) 0].A)); + + using (var foo = new Foo()) + { + var bar2 = new Bar { A = 10 }; + indexedProperties[foo] = bar2; + Assert.That(bar2.A, Is.EqualTo(indexedProperties[foo].A)); + } } } diff --git a/tests/Common/Common.cpp b/tests/Common/Common.cpp index 4b64ca59..98b3b56b 100644 --- a/tests/Common/Common.cpp +++ b/tests/Common/Common.cpp @@ -449,6 +449,11 @@ TypeMappedIndex::TypeMappedIndex() { } +Bar& TestIndexedProperties::operator[](const Foo& key) +{ + return bar; +} + InternalCtorAmbiguity::InternalCtorAmbiguity(void* param) { // cause a crash to indicate this is the incorrect ctor to invoke diff --git a/tests/Common/Common.h b/tests/Common/Common.h index 8064f9ee..c746e92d 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -568,6 +568,7 @@ public: foo_t operator[](TestProperties b); Bar& operator[](unsigned long i); Bar& operator[](const TypeMappedIndex& key); + Bar& operator[](const Foo& key); // Test that we do not generate 'ref int' parameters as C# does not allow it int operator[](CS_OUT char key);